Commit e56e3468 by tiger

Merge branch 'v1.0.1' of http://192.168.3.233:8090/platform/platform-process-server into v1.0.1

# Conflicts:
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/NodeTplMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstBatchMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstLinkMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstNodeBatchMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstNodeMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopTplGrantMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopTplLinkMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopTplMapper.java
#	platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopTplNodeMapper.java
#	platform-process/src/main/resources/mapper/NodeTplMapper.xml
#	platform-process/src/main/resources/mapper/SopInstMapper.xml
#	platform-process/src/main/resources/mapper/SopInstNodeMapper.xml
#	platform-process/src/main/resources/mapper/SopTplNodeMapper.xml
2 parents 81fc2c09 49fcf848
Showing 49 changed files with 2195 additions and 45 deletions
package cn.com.glsx.process.modules.entity;
import javax.persistence.*;
@Table(name = "sop_data_source")
public class SopDataSource {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Integer id;
/**
* 数据源类型 MYSQL,ORACLE,MSSQL,POSTGRESQL
*/
@Column(name = "db_type")
private String dbType;
/**
* ip地址
*/
@Column(name = "db_server")
private String dbServer;
/**
* 端口
*/
@Column(name = "db_port")
private Integer dbPort;
/**
* 账号
*/
@Column(name = "db_user_name")
private String dbUserName;
/**
* 密码
*/
@Column(name = "db_pwd")
private String dbPwd;
/**
* 数据源名称
*/
private String name;
@Column(name = "db_name")
private String dbName;
/**
* @return id
*/
public Integer getId() {
return id;
}
/**
* @param id
*/
public void setId(Integer id) {
this.id = id;
}
/**
* 获取数据源类型 MYSQL,ORACLE,MSSQL,POSTGRESQL
*
* @return db_type - 数据源类型 MYSQL,ORACLE,MSSQL,POSTGRESQL
*/
public String getDbType() {
return dbType;
}
/**
* 设置数据源类型 MYSQL,ORACLE,MSSQL,POSTGRESQL
*
* @param dbType 数据源类型 MYSQL,ORACLE,MSSQL,POSTGRESQL
*/
public void setDbType(String dbType) {
this.dbType = dbType == null ? null : dbType.trim();
}
/**
* 获取ip地址
*
* @return db_server - ip地址
*/
public String getDbServer() {
return dbServer;
}
/**
* 设置ip地址
*
* @param dbServer ip地址
*/
public void setDbServer(String dbServer) {
this.dbServer = dbServer == null ? null : dbServer.trim();
}
/**
* 获取账号
*
* @return db_user_name - 账号
*/
public String getDbUserName() {
return dbUserName;
}
/**
* 设置账号
*
* @param dbUserName 账号
*/
public void setDbUserName(String dbUserName) {
this.dbUserName = dbUserName == null ? null : dbUserName.trim();
}
/**
* 获取密码
*
* @return db_pwd - 密码
*/
public String getDbPwd() {
return dbPwd;
}
/**
* 设置密码
*
* @param dbPwd 密码
*/
public void setDbPwd(String dbPwd) {
this.dbPwd = dbPwd == null ? null : dbPwd.trim();
}
/**
* 获取数据源名称
*
* @return name - 数据源名称
*/
public String getName() {
return name;
}
/**
* 设置数据源名称
*
* @param name 数据源名称
*/
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
/**
* @return db_name
*/
public String getDbName() {
return dbName;
}
/**
* @param dbName
*/
public void setDbName(String dbName) {
this.dbName = dbName == null ? null : dbName.trim();
}
public Integer getDbPort() {
return dbPort;
}
public void setDbPort(Integer dbPort) {
this.dbPort = dbPort;
}
}
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,13 @@ import javax.persistence.*; ...@@ -5,6 +5,13 @@ import javax.persistence.*;
@Table(name = "sop_inst") @Table(name = "sop_inst")
public class SopInst { public class SopInst {
/**
* 启用状态:0,未启用;1,启用;-1,已删除/过期;
*/
public static final Byte INST_STATUS_UNUSED = 0;
public static final Byte INST_STATUS_DELETED = -1;
/** /**
* 实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态 * 实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态
*/ */
...@@ -48,6 +55,13 @@ public class SopInst { ...@@ -48,6 +55,13 @@ public class SopInst {
@Column(name = "inst_status") @Column(name = "inst_status")
private Byte instStatus; private Byte instStatus;
/**
* 实例默认输入参数
*/
@Column(name = "inst_param")
private String instParam;
/** /**
* sop有效期,每个sop都设置一个有效期,到期自动停止。 * sop有效期,每个sop都设置一个有效期,到期自动停止。
*/ */
...@@ -196,6 +210,14 @@ public class SopInst { ...@@ -196,6 +210,14 @@ public class SopInst {
this.instStatus = instStatus; this.instStatus = instStatus;
} }
public String getInstParam() {
return instParam;
}
public void setInstParam(String instParam) {
this.instParam = instParam;
}
/** /**
* 获取sop有效期,每个sop都设置一个有效期,到期自动停止。 * 获取sop有效期,每个sop都设置一个有效期,到期自动停止。
* *
......
...@@ -4,6 +4,14 @@ import javax.persistence.*; ...@@ -4,6 +4,14 @@ import javax.persistence.*;
@Table(name = "sop_inst_node") @Table(name = "sop_inst_node")
public class SopInstNode { public class SopInstNode {
public static final byte NODE_SKIP_FALSE = 0;
public static final byte NODE_SKIP_TRUE = 1;
public static final int NODE_STATUS_DELETED = 0;
public static final int NODE_STATUS_NORMAL = 1;
/** /**
* 实例节点id * 实例节点id
*/ */
...@@ -51,6 +59,18 @@ public class SopInstNode { ...@@ -51,6 +59,18 @@ public class SopInstNode {
private String nodeShow; private String nodeShow;
/** /**
* 输入参数格式:Json,开始节点的输入参数全局共用
*/
@Column(name = "node_param")
private String nodeParam;
/**
* 节点源码,配合node_type使用,比如java源码,python脚本,sql脚本+数据源等
*/
@Column(name = "node_content")
private String nodeContent;
/**
* 节点可见状态 * 节点可见状态
*/ */
@Column(name = "node_visible") @Column(name = "node_visible")
...@@ -220,6 +240,22 @@ public class SopInstNode { ...@@ -220,6 +240,22 @@ public class SopInstNode {
this.nodeShow = nodeShow == null ? null : nodeShow.trim(); this.nodeShow = nodeShow == null ? null : nodeShow.trim();
} }
public String getNodeParam() {
return nodeParam;
}
public void setNodeParam(String nodeParam) {
this.nodeParam = nodeParam;
}
public String getNodeContent() {
return nodeContent;
}
public void setNodeContent(String nodeContent) {
this.nodeContent = nodeContent;
}
/** /**
* 获取节点可见状态 * 获取节点可见状态
* *
......
...@@ -37,6 +37,18 @@ public class SopTpl { ...@@ -37,6 +37,18 @@ public class SopTpl {
private Byte tplStatus; private Byte tplStatus;
/** /**
* JSON结构,sop默认输入参数定义,可以在分配门店时配置的参数,比如旅程阶段列表
*/
@Column(name = "tpl_param_def")
private String tplParamDef;
/**
* JSON结构,sop默认输入参数定义,可以在分配门店时配置的参数,比如旅程阶段列表
*/
@Column(name = "tpl_result_def")
private String tplResultDef;
/**
* 是否单实例模式:0,多实例;1,单实例; * 是否单实例模式:0,多实例;1,单实例;
*/ */
@Column(name = "tpl_singleton") @Column(name = "tpl_singleton")
...@@ -49,6 +61,11 @@ public class SopTpl { ...@@ -49,6 +61,11 @@ public class SopTpl {
private Date updateTime; private Date updateTime;
/** /**
* 分发门店数
*/
private int grantCount;
/**
* 获取模板id,模板代码,建议使用模板名拼音首字母缩写,不要超过8位 * 获取模板id,模板代码,建议使用模板名拼音首字母缩写,不要超过8位
* *
* @return tpl_id - 模板id,模板代码,建议使用模板名拼音首字母缩写,不要超过8位 * @return tpl_id - 模板id,模板代码,建议使用模板名拼音首字母缩写,不要超过8位
...@@ -129,6 +146,22 @@ public class SopTpl { ...@@ -129,6 +146,22 @@ public class SopTpl {
return tplStatus; return tplStatus;
} }
public String getTplParamDef() {
return tplParamDef;
}
public void setTplParamDef(String tplParamDef) {
this.tplParamDef = tplParamDef;
}
public String getTplResultDef() {
return tplResultDef;
}
public void setTplResultDef(String tplResultDef) {
this.tplResultDef = tplResultDef;
}
/** /**
* 设置启用状态:0,禁用;1,启用; * 设置启用状态:0,禁用;1,启用;
* *
...@@ -183,4 +216,12 @@ public class SopTpl { ...@@ -183,4 +216,12 @@ public class SopTpl {
public void setUpdateTime(Date updateTime) { public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public int getGrantCount() {
return grantCount;
}
public void setGrantCount(int grantCount) {
this.grantCount = grantCount;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,13 @@ import javax.persistence.*; ...@@ -5,6 +5,13 @@ import javax.persistence.*;
@Table(name = "sop_tpl_grant") @Table(name = "sop_tpl_grant")
public class SopTplGrant { public class SopTplGrant {
/**
* 授权状态:0,未启用;1,启用;-1,删除;
*/
public static final Byte GRANT_STATUS_DELETED = -1;
public static final Byte GRANT_STATUS_NORMAL = 1;
/** /**
* 授权id * 授权id
*/ */
......
...@@ -42,6 +42,18 @@ public class SopTplNode { ...@@ -42,6 +42,18 @@ public class SopTplNode {
private String nodeShow; private String nodeShow;
/** /**
* 输入参数格式:Json,开始节点的输入参数全局共用
*/
@Column(name = "node_param_def")
private String nodeParamDef;
/**
* 节点源码,配合node_type使用,比如java源码,python脚本,sql脚本+数据源等
*/
@Column(name = "node_content_def")
private String nodeContentDef;
/**
* 节点的访问key,复制时不可变 * 节点的访问key,复制时不可变
*/ */
@Column(name = "node_key") @Column(name = "node_key")
...@@ -179,6 +191,22 @@ public class SopTplNode { ...@@ -179,6 +191,22 @@ public class SopTplNode {
this.nodeShow = nodeShow == null ? null : nodeShow.trim(); this.nodeShow = nodeShow == null ? null : nodeShow.trim();
} }
public String getNodeParamDef() {
return nodeParamDef;
}
public void setNodeParamDef(String nodeParamDef) {
this.nodeParamDef = nodeParamDef;
}
public String getNodeContentDef() {
return nodeContentDef;
}
public void setNodeContentDef(String nodeContentDef) {
this.nodeContentDef = nodeContentDef;
}
/** /**
* 获取节点的访问key,复制时不可变 * 获取节点的访问key,复制时不可变
* *
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.NodeTpl; import cn.com.glsx.process.modules.entity.NodeTpl;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface NodeTplMapper extends CommonBaseMapper<NodeTpl> { public interface NodeTplMapper extends CommonBaseMapper<NodeTpl> {
......
package cn.com.glsx.process.modules.mapper;
import cn.com.glsx.process.modules.entity.SopDataSource;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SopDataSourceMapper extends CommonBaseMapper<SopDataSource> {
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInstBatch; import cn.com.glsx.process.modules.entity.SopInstBatch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopInstBatchMapper extends CommonBaseMapper<SopInstBatch> { public interface SopInstBatchMapper extends CommonBaseMapper<SopInstBatch> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInstLink; import cn.com.glsx.process.modules.entity.SopInstLink;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopInstLinkMapper extends CommonBaseMapper<SopInstLink> { public interface SopInstLinkMapper extends CommonBaseMapper<SopInstLink> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopInstMapper extends CommonBaseMapper<SopInst> { public interface SopInstMapper extends CommonBaseMapper<SopInst> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInstNodeBatch; import cn.com.glsx.process.modules.entity.SopInstNodeBatch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopInstNodeBatchMapper extends CommonBaseMapper<SopInstNodeBatch> { public interface SopInstNodeBatchMapper extends CommonBaseMapper<SopInstNodeBatch> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> { public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper; import cn.com.glsx.process.modules.entity.SopTplGrant;
import cn.com.glsx.process.modules.model.SopTplGrantSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import cn.com.glsx.process.modules.entity.SopTplGrant; import java.util.List;
@Mapper @Mapper
public interface SopTplGrantMapper extends CommonBaseMapper<SopTplGrant> { public interface SopTplGrantMapper extends CommonBaseMapper<SopTplGrant> {
int countByTplId(@Param("tplId") String tplId);
List<SopTplGrant> list(SopTplGrantSearch search);
void del(@Param("id") Integer id);
/**
* 统计所有状态的派发数量
*
* @param tplId
* @return
*/
int countAllByTplId(@Param("tplId") String tplId);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopTplLink; import cn.com.glsx.process.modules.entity.SopTplLink;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopTplLinkMapper extends CommonBaseMapper<SopTplLink> { public interface SopTplLinkMapper extends CommonBaseMapper<SopTplLink> {
......
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper; import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.model.SopTplSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import cn.com.glsx.process.modules.entity.SopTpl; import java.util.List;
@Mapper @Mapper
public interface SopTplMapper extends CommonBaseMapper<SopTpl> { public interface SopTplMapper extends CommonBaseMapper<SopTpl> {
List<SopTpl> page(SopTplSearch search);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import cn.com.glsx.process.modules.entity.SopTplNode; import cn.com.glsx.process.modules.entity.SopTplNode;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SopTplNodeMapper extends CommonBaseMapper<SopTplNode> { public interface SopTplNodeMapper extends CommonBaseMapper<SopTplNode> {
......
package cn.com.glsx.process.modules.model;
import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class SopTplDTO {
/**
* 模板id,模板代码,建议使用模板名拼音首字母缩写,不要超过8位
*/
private String tplId;
/**
* 模板名
*/
private String tplName;
/**
* cron表达式,sop执行周期
*/
private String tplCron;
/**
* sop简介
*/
private String tplRemark;
/**
* 启用状态:0,禁用;1,启用;
*/
private Byte tplStatus;
/**
* JSON结构,sop默认输入参数定义,可以在分配门店时配置的参数,比如旅程阶段列表
*/
private String tplParamDef;
/**
* JSON结构,sop默认输入参数定义,可以在分配门店时配置的参数,比如旅程阶段列表
*/
private String tplResultDef;
/**
* 是否单实例模式:0,多实例;1,单实例;
*/
private Byte tplSingleton;
private Date createTime;
private Date updateTime;
/**
* 分发门店数
*/
private int grantCount;
/**
* sop任务节点
*/
private List<SopTplNode> nodes;
/**
* sop任务节点连接
*/
private List<SopTplLink> links;
public String getTplId() {
return tplId;
}
public void setTplId(String tplId) {
this.tplId = tplId;
}
public String getTplName() {
return tplName;
}
public void setTplName(String tplName) {
this.tplName = tplName;
}
public String getTplCron() {
return tplCron;
}
public void setTplCron(String tplCron) {
this.tplCron = tplCron;
}
public String getTplRemark() {
return tplRemark;
}
public void setTplRemark(String tplRemark) {
this.tplRemark = tplRemark;
}
public Byte getTplStatus() {
return tplStatus;
}
public void setTplStatus(Byte tplStatus) {
this.tplStatus = tplStatus;
}
public String getTplParamDef() {
return tplParamDef;
}
public void setTplParamDef(String tplParamDef) {
this.tplParamDef = tplParamDef;
}
public String getTplResultDef() {
return tplResultDef;
}
public void setTplResultDef(String tplResultDef) {
this.tplResultDef = tplResultDef;
}
public Byte getTplSingleton() {
return tplSingleton;
}
public void setTplSingleton(Byte tplSingleton) {
this.tplSingleton = tplSingleton;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public int getGrantCount() {
return grantCount;
}
public void setGrantCount(int grantCount) {
this.grantCount = grantCount;
}
public List<SopTplNode> getNodes() {
return nodes;
}
public void setNodes(List<SopTplNode> nodes) {
this.nodes = nodes;
}
public List<SopTplLink> getLinks() {
return links;
}
public void setLinks(List<SopTplLink> links) {
this.links = links;
}
}
package cn.com.glsx.process.modules.model;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.Date;
@Data
public class SopTplGrantSearch {
private Integer grantId;
/**
* 实例分组:当前场景下,分组id就是门店id
*/
private String groupId;
private String groupName;
/**
* 模板id
*/
@NotEmpty(message = "tplId参数不能为空!")
private String tplId;
private Date createTime;
private Date updateTime;
/**
* 授权状态:0,未启用;1,启用;-1,删除;
*/
private Byte grantStatus;
}
package cn.com.glsx.process.modules.model;
import cn.hutool.db.Page;
import lombok.Data;
@Data
public class SopTplSearch extends Page {
private String id;
private String name;
private Integer status;
}
...@@ -50,6 +50,29 @@ ...@@ -50,6 +50,29 @@
<artifactId>rpc-scrm-proxy-api</artifactId> <artifactId>rpc-scrm-proxy-api</artifactId>
<version>3.7.0-SNAPSHOT</version> <version>3.7.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.1-atlassian-hosted</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.common.sysenum;
/**
*
* @ClassName: DatabaseTypeEnum
* @Description: TODO(支持的数据库)
* @author: 缪聪(mcg-helper@qq.com)
* @date: 2018年3月9日 下午2:55:27
*
*/
public enum DatabaseTypeEnum {
MYSQL("MYSQL", "MYSQL", "com.mysql.jdbc.Driver"), ORACLE("ORACLE", "ORACLE", "oracle.jdbc.driver.OralceDriver"), MSSQL("MSSQL", "MSSQL", "com.microsoft.sqlserver.jdbc.SQLServerDriver"), POSTGRESQL("POSTGRESQL", "POSTGRESQL", "org.postgresql.Driver");
private String name;
private String value;
private String driverClass;
private DatabaseTypeEnum(String name, String value, String driverClass) {
this.name = name;
this.value = value;
this.driverClass = driverClass;
}
public static DatabaseTypeEnum getDatabaseByName(String name) {
for (DatabaseTypeEnum c : DatabaseTypeEnum.values()) {
if (c.getName().equals(name)) {
return c;
}
}
return null;
}
public static String getValueByName(String name) {
for (DatabaseTypeEnum c : DatabaseTypeEnum.values()) {
if (c.getName().equals(name)) {
return c.value;
}
}
return null;
}
public static String getNameByValue(String value) {
for (DatabaseTypeEnum c : DatabaseTypeEnum.values()) {
if (c.getValue().equals(value)) {
return c.name;
}
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getDriverClass() {
return driverClass;
}
public void setDriverClass(String driverClass) {
this.driverClass = driverClass;
}
}
\ No newline at end of file \ No newline at end of file
...@@ -61,6 +61,7 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -61,6 +61,7 @@ public class WebConfig implements WebMvcConfigurer {
//1.加入的顺序就是拦截器执行的顺序, //1.加入的顺序就是拦截器执行的顺序,
//2.按顺序执行所有拦截器的preHandle //2.按顺序执行所有拦截器的preHandle
//3.所有的preHandle 执行完再执行全部postHandle 最后是postHandle //3.所有的preHandle 执行完再执行全部postHandle 最后是postHandle
//4.sop登录不拦截
registry.addInterceptor(visitInterceptor) registry.addInterceptor(visitInterceptor)
.addPathPatterns("/**") .addPathPatterns("/**")
.excludePathPatterns("/") .excludePathPatterns("/")
...@@ -69,6 +70,7 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -69,6 +70,7 @@ public class WebConfig implements WebMvcConfigurer {
.excludePathPatterns("/*.shtml") .excludePathPatterns("/*.shtml")
.excludePathPatterns("/admin/**") .excludePathPatterns("/admin/**")
.excludePathPatterns("/api/**") .excludePathPatterns("/api/**")
.excludePathPatterns("/sop/**")
.excludePathPatterns(uploadProperties.getFilepath()) .excludePathPatterns(uploadProperties.getFilepath())
.excludePathPatterns("/swagger-resources/**", "/swagger-ui/**", "/v3/**", "/doc.html"); .excludePathPatterns("/swagger-resources/**", "/swagger-ui/**", "/v3/**", "/doc.html");
registry.addInterceptor(logInterceptor).addPathPatterns("/**"); registry.addInterceptor(logInterceptor).addPathPatterns("/**");
......
package cn.com.glsx.process.modules.controller;
import cn.com.glsx.process.modules.BaseController;
import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.modules.model.SopTplSearch;
import cn.com.glsx.process.modules.service.SopTplService;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.annotation.ResponseResultBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Slf4j
@Tag(name = "SOP模板开放接口")
@RestController
@RequestMapping(value = "/sop/sopTpls")
@ResponseResultBody
public class SopTplController extends BaseController {
@Resource
private SopTplService sopTplService;
@Operation(summary = "SOP模板列表", description = "SOP模板列表")
@GetMapping
public PageInfo<SopTpl> page(SopTplSearch search) {
PageInfo<SopTpl> list = sopTplService.page(search);
return list;
}
@Operation(summary = "SOP模板详情", description = "SOP模板详情")
@GetMapping("/{id}")
public SopTplDTO getById(@PathVariable("id") String id) {
return sopTplService.getById(id);
}
}
package cn.com.glsx.process.modules.controller;
import cn.com.glsx.process.modules.BaseController;
import cn.com.glsx.process.modules.entity.SopTplGrant;
import cn.com.glsx.process.modules.model.SopTplGrantSearch;
import cn.com.glsx.process.modules.service.SopTplGrantService;
import com.glsx.plat.core.annotation.ResponseResultBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Tag(name = "SOP模板授权门店接口")
@RestController
@RequestMapping(value = "/sop/sopTplGrants")
@ResponseResultBody
public class SopTplGrantController extends BaseController {
@Resource
private SopTplGrantService sopTplGrantService;
@Operation(summary = "分配门店列表", description = "分配门店列表")
@GetMapping("/list")
public List<SopTplGrant> list(@Validated SopTplGrantSearch search) {
return sopTplGrantService.list(search);
}
@Operation(summary = "下发门店", description = "下发门店")
@PostMapping
public String add(@RequestBody @Validated List<SopTplGrant> sopTplGrants) {
sopTplGrantService.add(sopTplGrants);
return "success";
}
@Operation(summary = "撤销下发门店", description = "撤销下发门店")
@DeleteMapping("/{id}")
public String del(@PathVariable("id") Integer id) {
sopTplGrantService.del(id);
return "success";
}
}
...@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
@Slf4j @Slf4j
@Tag(name = "用户接口(Demo)") @Tag(name = "用户接口(Demo)")
@RestController @RestController
@RequestMapping(value = "/user") @RequestMapping(value = "/sop/user")
@ResponseResultBody @ResponseResultBody
public class UserController extends BaseController { public class UserController extends BaseController {
...@@ -62,9 +62,9 @@ public class UserController extends BaseController { ...@@ -62,9 +62,9 @@ public class UserController extends BaseController {
@Operation(summary = "用户详情", description = "查询用户详情") @Operation(summary = "用户详情", description = "查询用户详情")
@GetMapping(value = "/info/{id}") @GetMapping(value = "/info/{id}")
public UserDTO info(@PathVariable("id") Long id) { public UserDTO info(@PathVariable("id") Long id) {
User user = userDemoService.getById(id); /* User user = userDemoService.getById(id);
UserDTO userDTO = UserConverter.INSTANCE.do2dto(user); UserDTO userDTO = UserConverter.INSTANCE.do2dto(user);*/
return userDTO; return null;
} }
} }
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.model.SopTplDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SopTplConverter {
SopTplConverter INSTANCE = Mappers.getMapper(SopTplConverter.class);
SopTplDTO do2dto(SopTpl sopTpl);
SopTpl dto2do(SopTplDTO sopTplDTO);
@Mappings({
@Mapping(source = "tplName", target = "instName"),
@Mapping(source = "tplCron", target = "instCron"),
@Mapping(source = "tplRemark", target = "instRemark"),
@Mapping(source = "tplParamDef", target = "instParam")})
SopInst do2inst(SopTpl sopTpl);
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.entity.SopTplLink;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SopTplLinKConverter {
SopTplLinKConverter INSTANCE = Mappers.getMapper(SopTplLinKConverter.class);
@Mappings({@Mapping(ignore = true, source = "linkId", target = "linkId")})
SopInstLink tpl2inst(SopTplLink link);
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopTplNode;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SopTplNodeConverter {
SopTplNodeConverter INSTANCE = Mappers.getMapper(SopTplNodeConverter.class);
@Mappings({
@Mapping(source = "nodeParamDef", target = "nodeParam"),
@Mapping(source = "nodeContentDef", target = "nodeContent")})
SopInstNode tpl2inst(SopTplNode node);
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.mapper.SopDataSourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopDataSourceService {
@Autowired
private SopDataSourceMapper sopDataSourceMapper;
public SopDataSource getById(Integer id){
return sopDataSourceMapper.selectByPrimaryKey(id);
};
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.converter.SopTplConverter;
import cn.com.glsx.process.modules.converter.SopTplLinKConverter;
import cn.com.glsx.process.modules.converter.SopTplNodeConverter;
import cn.com.glsx.process.modules.entity.*;
import cn.com.glsx.process.modules.mapper.*;
import cn.com.glsx.process.modules.model.SopTplGrantSearch;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class SopTplGrantService {
@Resource
private SopTplGrantMapper sopTplGrantMapper;
@Resource
private SopInstMapper sopInstMapper;
@Resource
private SopInstLinkMapper sopInstLinkMapper;
@Resource
private SopInstNodeMapper sopInstNodeMapper;
@Resource
private SopTplMapper sopTplMapper;
@Resource
private SopTplNodeMapper sopTplNodeMapper;
@Resource
private SopTplLinkMapper sopTplLinkMapper;
public List<SopTplGrant> list(SopTplGrantSearch search) {
return sopTplGrantMapper.list(search);
}
@Transactional
public void del(Integer id) {
sopTplGrantMapper.del(id);
}
@Transactional
public void add(List<SopTplGrant> sopTplGrants) {
Date date = new Date();
//新增派发门店记录
sopTplGrants.forEach(sopTplGrant -> {
sopTplGrant.setGrantStatus(SopTplGrant.GRANT_STATUS_NORMAL);
sopTplGrant.setCreateTime(date);
sopTplGrant.setUpdateTime(date);
});
sopTplGrantMapper.insertList(sopTplGrants);
String tplId = sopTplGrants.get(0).getTplId();
SopTpl sopTpl = sopTplMapper.selectByPrimaryKey(tplId);
Assert.state(sopTpl != null, "模板不存在!");
SopTplNode nodeQuery = new SopTplNode();
nodeQuery.setTplId(tplId);
List<SopTplNode> nodes = sopTplNodeMapper.select(nodeQuery);
SopTplLink linkQuery = new SopTplLink();
linkQuery.setTplId(tplId);
List<SopTplLink> links = sopTplLinkMapper.select(linkQuery);
int count = sopTplGrantMapper.countAllByTplId(tplId);
SopTplConverter sopTplConverter = SopTplConverter.INSTANCE;
SopTplLinKConverter sopTplLinKConverter = SopTplLinKConverter.INSTANCE;
SopTplNodeConverter sopTplNodeConverter = SopTplNodeConverter.INSTANCE;
for (SopTplGrant sopTplGrant : sopTplGrants) {
Integer grantId = sopTplGrant.getGrantId();
//克隆模板内容
SopInst sopInst = sopTplConverter.do2inst(sopTpl);
sopInst.setInstId(tplId + grantId);
sopInst.setGrantId(grantId);
sopInst.setCreateTime(date);
sopInst.setUpdateTime(date);
sopInst.setInstStatus(SopInst.INST_STATUS_UNUSED);
sopInstMapper.insert(sopInst);
//克隆连接
String instId = sopInst.getInstId();
List<SopInstLink> sopInstLinks = new ArrayList<>();
links.forEach(sopTplLink -> {
SopInstLink sopInstLink = sopTplLinKConverter.tpl2inst(sopTplLink);
sopInstLink.setInstId(instId);
sopInstLinks.add(sopInstLink);
});
sopInstLinkMapper.insertList(sopInstLinks);
//克隆节点
List<SopInstNode> sopInstNodes = new ArrayList<>();
nodes.forEach(sopTplNode -> {
SopInstNode sopInstNode = sopTplNodeConverter.tpl2inst(sopTplNode);
sopInstNode.setInstId(instId);
sopInstNode.setNodeSkip(SopInstNode.NODE_SKIP_FALSE);
sopInstNode.setNodeStatus(SopInstNode.NODE_STATUS_NORMAL);
sopInstNodes.add(sopInstNode);
});
sopInstNodeMapper.insertList(sopInstNodes);
}
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.converter.SopTplConverter;
import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.mapper.SopTplLinkMapper;
import cn.com.glsx.process.modules.mapper.SopTplMapper;
import cn.com.glsx.process.modules.mapper.SopTplNodeMapper;
import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.modules.model.SopTplSearch;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
@Service
public class SopTplService {
@Resource
private SopTplMapper sopTplMapper;
@Resource
private SopTplNodeMapper sopTplNodeMapper;
@Resource
private SopTplLinkMapper sopTplLinkMapper;
public PageInfo<SopTpl> page(SopTplSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize());
List<SopTpl> list = sopTplMapper.page(search);
return new PageInfo<>(list);
}
/**
* 查询sop模板详情
*
* @param id
* @return
*/
public SopTplDTO getById(String id) {
SopTpl sopTpl = sopTplMapper.selectByPrimaryKey(id);
if (Objects.isNull(sopTpl)) {
return null;
}
SopTplDTO sopTplDTO = SopTplConverter.INSTANCE.do2dto(sopTpl);
SopTplNode nodeQuery = new SopTplNode();
nodeQuery.setTplId(id);
List<SopTplNode> nodes = sopTplNodeMapper.select(nodeQuery);
sopTplDTO.setNodes(nodes);
SopTplLink linkQuery = new SopTplLink();
linkQuery.setTplId(id);
List<SopTplLink> links = sopTplLinkMapper.select(linkQuery);
sopTplDTO.setLinks(links);
return sopTplDTO;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import org.apache.commons.dbutils.DbUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public abstract class AbstractConnect {
private static Logger logger = LoggerFactory.getLogger(AbstractConnect.class);
public DbConnect dbConnect;
public AbstractConnect(DataSource dataSource) {
super();
initDbConnect(dataSource);
}
/**
* 初始化
*
* @see [类、类#方法、类#成员]
*/
private void initDbConnect(DataSource dataSource) {
if (dbConnect == null) {
dbConnect = new DbConnect(dataSource);
}
}
/**
* 带可变参数查询,返回执行结果
*
* @param sql
* 查询sql
* @param para
* 可变参数
* @return
* @throws SQLException
*/
public List<Map<String, Object>> querySql(String sql, Object... para) throws SQLException {
return dbConnect.querySql(sql, para);
}
/**
* 带可变参数查询,返回执行结果
*
* @param <T>
*
* @param sql
* 查询sql
* @param para
* 可变参数
* @return
* @throws SQLException
*/
@SuppressWarnings("unchecked")
public <T> List<T> executeQuery(T clazz, String sql, Object... para) throws SQLException {
return dbConnect.querySql(clazz, sql, para);
}
/**
* 带可变参数查询,返回long类型数据
*
* @param countSql
* 查询记录条数的sql
* @param para
* 可变参数
* @return
* @throws SQLException
* @throws SQLException
*/
public Long queryForLong(String countSql, Object... para) throws SQLException {
return dbConnect.queryForLong(countSql, para);
}
/**
* 带可变参数, 执行sql插入,返回新增记录的自增主键<BR>
* 注意: 若插入的表无自增主键则返回 0,异常的话则返回 null
*
* @param sql
* @param para
* @return
* @throws SQLException
* @see [类、类#方法、类#成员]
*/
public Long executeInsert(String sql, Object... para) throws SQLException {
return dbConnect.insertSql(sql, para);
}
/**
* 带可变参数, 执行sql,返回执行影响的记录条数
*
* @param sql
* 执行的sql 语句
* @param para
* 可变参数
* @return
* @throws SQLException
*/
public int executeUpdate(String sql, Object... para) throws SQLException {
return dbConnect.executeUpdate(sql, para);
}
public boolean testConnect() {
boolean result = false;
try {
Connection connection = dbConnect.getDataSource().getConnection();
if (connection != null) {
DbUtils.closeQuietly(connection);
result = true;
}
} catch (SQLException e) {
logger.error("测试连接出错,异常信息:", e);
return result;
}
return result;
}
}
\ No newline at end of file \ No newline at end of file
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* 带事务支持的数据库底层操作类
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class DbConnect {
private static Logger logger = LoggerFactory.getLogger(DbConnect.class);
private DataSource dataSource;
private ThreadLocal<Connection> threadLocal = new ThreadLocal<Connection>();
public DbConnect(DataSource dataSource) {
this.dataSource = dataSource;
}
/**
* 创建数据库连接
*
* @return
* @see [类、类#方法、类#成员]
*/
public Connection getConnection() {
Connection connection = threadLocal.get();
try {
if (connection == null) {
connection = dataSource.getConnection();
threadLocal.set(connection);
}
} catch (SQLException e) {
logger.error("获取数据库连接失败,异常信息:", e.getMessage());
throw new RuntimeException("获取数据库连接失败.....");
}
return connection;
}
/**
* 带可变参数查询,返回执行结果
*
* @param sql 查询sql
* @param para 可变参数
* @return
*/
public List<Map<String, Object>> querySql(String sql, Object... para) throws SQLException {
logger.debug("查询Sql: {}, 查询参数: {}", sql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner();
Connection conn = null;
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
try {
conn = getConnection();
result = runner.query(conn, sql, new MapListHandler(), para);
} catch (SQLException e) {
logger.error("查询出错,异常信息: {}", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
return result;
}
/**
*
* @Title: querySql
* @Description: TODO(带可变参数查询,返回执行结果)
* @param: @param clazz 转换的对象实例
* @param: @param sql 查询sql语句
* @param: @param para 查询参数
* @param: @return
* @param: @throws SQLException
* @return: List
* @throws
*/
public <T> List querySql(T clazz, String sql, Object... para) throws SQLException {
logger.debug("查询Sql: {}, 查询参数: {}", sql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner();
Connection conn = null;
List<T> result = new ArrayList<T>();
try {
conn = getConnection();
// 下划线分隔的表字段名转换为实体bean驼峰命名属性
BeanProcessor bean = new GenerousBeanProcessor();
RowProcessor processor = new BasicRowProcessor(bean);
result = (List<T>) runner.query(conn, sql, new BeanListHandler((Class) clazz, processor), para);
} catch (SQLException e) {
logger.error("查询出错,异常信息: {}------", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
return result;
}
/**
*
* @Title: queryForLong
* @Description: TODO(带可变参数查询,返回long类型数据)
* @param: @param countSql 查询记录总条数
* @param: @param para 参数
* @param: @return
* @param: @throws SQLException
* @return: Long
* @throws
*/
public Long queryForLong(String countSql, Object... para) throws SQLException {
logger.debug("queryForLong: {}, para: {}", countSql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner();
Long number = null;
Connection conn = null;
try {
conn = getConnection();
number = runner.query(conn, countSql, new ScalarHandler<Long>(), para);
} catch (SQLException e) {
logger.error("------queryForLong error: {}------", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
return number;
}
/**
*
* @Title: executeUpdate
* @Description: TODO(带可变参数, 执行sql,返回执行影响的记录条数)
* @param: @param sql 执行的sql语句
* @param: @param para 参数
* @param: @return
* @param: @throws SQLException
* @return: int
* @throws
*/
public int executeUpdate(String sql, Object... para) throws SQLException {
logger.debug("executeUpdate: {}, para: {}", sql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner();
Connection conn = null;
int count = 0;
try {
conn = getConnection();
count = runner.update(conn, sql, para);
} catch (SQLException e) {
logger.error("------executeUpdate error: {}------", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
return count;
}
/**
*
* @Title: insertSql
* @Description: TODO(带可变参数, 执行sql插入,返回新增记录的自增主键。注意: 若插入的表无自增主键则返回 0,异常的话则返回 null)
* @param: @param sql 执行的sql语句
* @param: @param para 参数
* @param: @return
* @param: @throws SQLException
* @return: Long
* @throws
*/
public Long insertSql(String sql, Object... para) throws SQLException {
logger.debug("InsertSql: {}, para: {}", sql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner();
Connection conn = null;
Long id = null;
try {
conn = getConnection();
id = (Long) runner.insert(conn, sql, new ScalarHandler<Object>(), para);
} catch (SQLException e) {
logger.error("------insertSql error: {}------", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
return id;
}
/**
*
* @Title: executeBatch
* @Description: TODO(批量更新)
* @param: @param sql 执行的sql语句
* @param: @param params 二维数组参数
* @param: @throws SQLException
* @return: void
* @throws
*/
public void executeBatch(String sql, Object[][] params) throws SQLException {
logger.debug("executeBatch: {}, params:{}", sql, ToStringBuilder.reflectionToString(params));
QueryRunner runner = new QueryRunner();
Connection conn = null;
try {
conn = getConnection();
runner.batch(conn, sql, params);
} catch (SQLException e) {
logger.error("------executeBatch Error:{}------", e.getMessage());
throw e;
} finally {
if (conn != null && conn.getAutoCommit() == true) {
freeConnection();
}
}
}
/**
*
* @Title: executeBatch
* @Description: TODO(批量更新)
* @param: @param sql 执行的sql语句
* @param: @param params 参数
* @param: @throws SQLException
* @return: void
* @throws
*/
public void executeBatch(String sql, List<Object[]> params) throws SQLException {
Object[][] paramArr = params.toArray(new Object[0][]);
executeBatch(sql, paramArr);
}
/**
*
* @Title: freeConnection
* @Description: TODO(释放数据库连接)
* @param:
* @return: void
* @throws
*/
public void freeConnection() {
logger.debug("------释放数据库连接------");
Connection conn = threadLocal.get();
if (conn != null) {
DbUtils.closeQuietly(conn);
threadLocal.remove(); // 解除当前线程上绑定conn
}
}
/**
*
* @Title: commit
* @Description: TODO(提交事务)
* @param:
* @return: void
* @throws
*/
public void commit() {
logger.debug("------提交事务-------");
try {
Connection conn = threadLocal.get();
if (conn != null) {
conn.commit();
}
} catch (SQLException e) {
logger.error("提交事务失败,异常信息:{}", e.getMessage());
}
}
/**
*
* @Title: rollback
* @Description: TODO(回滚事务)
* @param:
* @return: void
*/
public void rollback() {
logger.debug("------ 系统异常,回滚事务------");
try {
Connection conn = threadLocal.get();
if (conn != null) {
conn.rollback();
}
} catch (SQLException e) {
logger.error("回滚事务失败,异常信息:{}", e.getMessage());
}
}
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
}
\ No newline at end of file \ No newline at end of file
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import cn.com.glsx.process.common.sysenum.DatabaseTypeEnum;
import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.plugin.dbconn.mssql.MssqlConnectImpl;
import cn.com.glsx.process.plugin.dbconn.mysql.MysqlConnectImpl;
import cn.com.glsx.process.plugin.dbconn.oracle.OracleConnectImpl;
import cn.com.glsx.process.plugin.dbconn.postgresql.PostgresqlConnectImpl;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
import oracle.jdbc.pool.OracleDataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public class FlowDataAdapterImpl implements McgBizAdapter {
private static Logger logger = LoggerFactory.getLogger(FlowDataAdapterImpl.class);
private McgConnect mcgConnect;
public FlowDataAdapterImpl(SopDataSource mcgDataSource) {
if(DatabaseTypeEnum.MYSQL.getValue().equals(mcgDataSource.getDbType())) {
MysqlDataSource mysqlDataSource = new MysqlDataSource();
mysqlDataSource.setServerName(mcgDataSource.getDbServer());
mysqlDataSource.setPort(mcgDataSource.getDbPort());
mysqlDataSource.setDatabaseName(mcgDataSource.getDbName());
try {
mysqlDataSource.setCharacterEncoding("UTF-8");
mysqlDataSource.setCharacterSetResults("UTF-8");
} catch (SQLException e) {
throw new RuntimeException(e);
}
mysqlDataSource.setUser(mcgDataSource.getDbUserName());
mysqlDataSource.setPassword(mcgDataSource.getDbPwd());
try {
mysqlDataSource.setConnectTimeout(3000);
} catch (SQLException e) {
logger.error("mysql数据源适配失败,异常信息:", e);
}
mcgConnect = new MysqlConnectImpl(mysqlDataSource);
} else if(DatabaseTypeEnum.ORACLE.getValue().equals(mcgDataSource.getDbType())) {
try {
OracleDataSource oracleDataSource = new OracleDataSource();
oracleDataSource.setDriverType("thin");
oracleDataSource.setNetworkProtocol("tcp");
oracleDataSource.setServerName(mcgDataSource.getDbServer());
oracleDataSource.setDatabaseName(mcgDataSource.getDbName());
oracleDataSource.setPortNumber(mcgDataSource.getDbPort());
oracleDataSource.setUser(mcgDataSource.getDbUserName());
oracleDataSource.setPassword(mcgDataSource.getDbPwd());
oracleDataSource.setLoginTimeout(3000);
mcgConnect = new OracleConnectImpl(oracleDataSource);
} catch (SQLException e) {
logger.error("oracle数据源适配失败,异常信息:", e);
}
} else if(DatabaseTypeEnum.MSSQL.getValue().equals(mcgDataSource.getDbType())) {
try {
SQLServerDataSource sqlServerDataSource = new SQLServerDataSource();
sqlServerDataSource.setDatabaseName(mcgDataSource.getDbName());
sqlServerDataSource.setUser(mcgDataSource.getDbUserName());
sqlServerDataSource.setPassword(mcgDataSource.getDbPwd());
sqlServerDataSource.setServerName(mcgDataSource.getDbServer());
sqlServerDataSource.setPortNumber(mcgDataSource.getDbPort());
sqlServerDataSource.setLoginTimeout(3000);
mcgConnect = new MssqlConnectImpl(sqlServerDataSource);
} catch (Exception e) {
logger.error("oracle数据源适配失败,异常信息:", e);
}
} else if(DatabaseTypeEnum.POSTGRESQL.getValue().equals(mcgDataSource.getDbType())) {
PGPoolingDataSource pgDataSource = new PGPoolingDataSource();
try {
pgDataSource.setDatabaseName(mcgDataSource.getDbName());
pgDataSource.setUser(mcgDataSource.getDbUserName());
pgDataSource.setPassword(mcgDataSource.getDbPwd());
pgDataSource.setPortNumber(mcgDataSource.getDbPort());
pgDataSource.setServerName(mcgDataSource.getDbServer());
pgDataSource.setLoginTimeout(3000);
} catch (SQLException e) {
logger.error("postgresql数据源适配失败,异常信息:", e);
}
mcgConnect = new PostgresqlConnectImpl(pgDataSource);
}
}
@Override
public List<Map<String, Object>> tableQuery(String sql, Object... para) throws SQLException {
return mcgConnect.querySql(sql, para);
}
@Override
public int executeUpdate(String sql, Object... para) throws SQLException {
return mcgConnect.executeUpdate(sql, para);
}
@Override
public boolean testConnect() {
boolean flag = false;
try {
flag = mcgConnect.testConnect();
} catch (Exception e) {
logger.error("数据连接测试失败,异常信息:", e);
}
return flag;
}
}
\ No newline at end of file \ No newline at end of file
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public interface McgBizAdapter {
boolean testConnect();
List<Map<String, Object>> tableQuery(String sql, Object... para) throws SQLException;
public int executeUpdate(String sql, Object... para) throws SQLException;
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public interface McgConnect {
boolean testConnect();
List<Map<String, Object>> querySql(String sql, Object... para) throws SQLException;
int executeUpdate(String sql, Object... para) throws SQLException;
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class McgDataSource implements Serializable {
private static final long serialVersionUID = -7416980731775213841L;
@XmlElement
private String dataSourceId;
@XmlElement
private String name;
@XmlElement
private String dbType;
@XmlElement
private String dbServer;
@XmlElement
private Integer dbPort;
@XmlElement
private String dbName;
@XmlElement
private String dbUserName;
@XmlElement
private String dbPwd;
@XmlElement
private String note;
public String getDataSourceId() {
return dataSourceId;
}
public void setDataSourceId(String dataSourceId) {
this.dataSourceId = dataSourceId;
}
public String getDbType() {
return dbType;
}
public void setDbType(String dbType) {
this.dbType = dbType;
}
public String getDbServer() {
return dbServer;
}
public void setDbServer(String dbServer) {
this.dbServer = dbServer;
}
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
public String getDbUserName() {
return dbUserName;
}
public void setDbUserName(String dbUserName) {
this.dbUserName = dbUserName;
}
public String getDbPwd() {
return dbPwd;
}
public void setDbPwd(String dbPwd) {
this.dbPwd = dbPwd;
}
public Integer getDbPort() {
return dbPort;
}
public void setDbPort(Integer dbPort) {
this.dbPort = dbPort;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn.mssql;
import cn.com.glsx.process.plugin.dbconn.AbstractConnect;
import cn.com.glsx.process.plugin.dbconn.McgConnect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
public class MssqlConnectImpl extends AbstractConnect implements McgConnect {
private static Logger logger = LoggerFactory.getLogger(MssqlConnectImpl.class);
public MssqlConnectImpl(DataSource dataSource) {
super(dataSource);
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn.mysql;
import cn.com.glsx.process.plugin.dbconn.AbstractConnect;
import cn.com.glsx.process.plugin.dbconn.McgConnect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
public class MysqlConnectImpl extends AbstractConnect implements McgConnect {
private static Logger logger = LoggerFactory.getLogger(MysqlConnectImpl.class);
public MysqlConnectImpl(DataSource dataSource) {
super(dataSource);
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn.oracle;
import cn.com.glsx.process.plugin.dbconn.AbstractConnect;
import cn.com.glsx.process.plugin.dbconn.McgConnect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
public class OracleConnectImpl extends AbstractConnect implements McgConnect {
private static Logger logger = LoggerFactory.getLogger(OracleConnectImpl.class);
public OracleConnectImpl(DataSource dataSource) {
super(dataSource);
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.plugin.dbconn.postgresql;
import cn.com.glsx.process.plugin.dbconn.AbstractConnect;
import cn.com.glsx.process.plugin.dbconn.McgConnect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
public class PostgresqlConnectImpl extends AbstractConnect implements McgConnect {
private static Logger logger = LoggerFactory.getLogger(PostgresqlConnectImpl.class);
public PostgresqlConnectImpl(DataSource dataSource) {
super(dataSource);
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Types;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
public class JDBCTypesUtils {
private static Logger logger = LoggerFactory.getLogger(JDBCTypesUtils.class);
private static Map<String, Integer> jdbcTypes;
private static Map<Integer, String> jdbcTypeValues;
private static Map<Integer, Class<?>> jdbcJavaTypes;
static {
jdbcTypes = new TreeMap<String, Integer>();
jdbcTypeValues = new TreeMap<Integer, String>();
jdbcJavaTypes = new TreeMap<Integer, Class<?>>();
Field[] fields = Types.class.getFields();
try {
for (int i = 0, len = fields.length; i < len; ++i) {
if (Modifier.isStatic(fields[i].getModifiers())) {
String name = fields[i].getName();
Integer value = (Integer) fields[i].get(Types.class);
jdbcTypes.put(name, value);
jdbcTypeValues.put(value, name);
}
}
} catch (Exception e) {
logger.error(e.getMessage());
}
// 初始化jdbcJavaTypes:
jdbcJavaTypes.put(new Integer(Types.LONGNVARCHAR), String.class); // -16 字符串
jdbcJavaTypes.put(new Integer(Types.NCHAR), String.class); // -15 字符串
jdbcJavaTypes.put(new Integer(Types.NVARCHAR), String.class); // -9 字符串
jdbcJavaTypes.put(new Integer(Types.ROWID), String.class); // -8 字符串
jdbcJavaTypes.put(new Integer(Types.BIT), Boolean.class); // -7 布尔
jdbcJavaTypes.put(new Integer(Types.TINYINT), Byte.class); // -6 数字
jdbcJavaTypes.put(new Integer(Types.BIGINT), Long.class); // -5 数字
jdbcJavaTypes.put(new Integer(Types.LONGVARBINARY), Blob.class); // -4 二进制
jdbcJavaTypes.put(new Integer(Types.VARBINARY), Blob.class); // -3 二进制
jdbcJavaTypes.put(new Integer(Types.BINARY), Blob.class); // -2 二进制
jdbcJavaTypes.put(new Integer(Types.LONGVARCHAR), String.class); // -1 字符串
// jdbcJavaTypes.put(new Integer(Types.NULL), String.class); // 0 /
jdbcJavaTypes.put(new Integer(Types.CHAR), String.class); // 1 字符串
jdbcJavaTypes.put(new Integer(Types.NUMERIC), BigDecimal.class); // 2 数字
jdbcJavaTypes.put(new Integer(Types.DECIMAL), BigDecimal.class); // 3 数字
jdbcJavaTypes.put(new Integer(Types.INTEGER), Integer.class); // 4 数字
jdbcJavaTypes.put(new Integer(Types.SMALLINT), Short.class); // 5 数字
jdbcJavaTypes.put(new Integer(Types.FLOAT), Float.class); // 6 数字
jdbcJavaTypes.put(new Integer(Types.REAL), BigDecimal.class); // 7 数字
jdbcJavaTypes.put(new Integer(Types.DOUBLE), BigDecimal.class); // 8 数字
jdbcJavaTypes.put(new Integer(Types.VARCHAR), String.class); // 12 字符串
jdbcJavaTypes.put(new Integer(Types.BOOLEAN), Boolean.class); // 16 布尔
// jdbcJavaTypes.put(new Integer(Types.DATALINK), String.class); // 70 /
jdbcJavaTypes.put(new Integer(Types.DATE), Date.class); // 91 日期
jdbcJavaTypes.put(new Integer(Types.TIME), Date.class); // 92 日期
jdbcJavaTypes.put(new Integer(Types.TIMESTAMP), Date.class); // 93 日期
jdbcJavaTypes.put(new Integer(Types.OTHER), Object.class); // 1111 其他类型?
// jdbcJavaTypes.put(new Integer(Types.JAVA_OBJECT), Object.class); // 2000
// jdbcJavaTypes.put(new Integer(Types.DISTINCT), String.class); // 2001
// jdbcJavaTypes.put(new Integer(Types.STRUCT), String.class); // 2002
// jdbcJavaTypes.put(new Integer(Types.ARRAY), String.class); // 2003
jdbcJavaTypes.put(new Integer(Types.BLOB), Blob.class); // 2004 二进制
jdbcJavaTypes.put(new Integer(Types.CLOB), Clob.class); // 2005 大文本
// jdbcJavaTypes.put(new Integer(Types.REF), String.class); // 2006
// jdbcJavaTypes.put(new Integer(Types.SQLXML), String.class); // 2009
jdbcJavaTypes.put(new Integer(Types.NCLOB), Clob.class); // 2011 大文本
}
public static int getJdbcCode(String jdbcName) {
return jdbcTypes.get(jdbcName);
}
public static String getJdbcName(int jdbcCode) {
return jdbcTypeValues.get(jdbcCode);
}
public static Class<?> jdbcTypeToJavaType(int jdbcType) {
return jdbcJavaTypes.get(jdbcType);
}
public static boolean isJavaNumberType(int jdbcType) {
Class<?> type = jdbcJavaTypes.get(jdbcType);
return (type == null) ? false : (Number.class.isAssignableFrom(type)) ? true : false;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed 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.com.glsx.process.util;
import com.google.common.base.CaseFormat;
import org.apache.commons.lang.StringUtils;
/**
*
* @ClassName: Tools
* @Description: TODO(字符操作、hibernate validator)
* @author: 缪聪(mcg-helper@qq.com)
* @date: 2018年3月9日 下午5:41:39
*
*/
public class Tools {
public static String genFlowInstanceId(String httpSessionId, String flowId) {
return httpSessionId + "##" + flowId;
}
/*
* 分割字符串".",截取最后一段(如导入类型:java.utils.Date)截取最后的Date
*/
public static String splitLast(String data) {
if(StringUtils.isEmpty(data)) {
return null;
}
String[] split = data.split("\\.");
return split[split.length-1];
}
/*
* 字符串转换驼峰变量名
*/
public static String convertFieldName(String name) {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
}
/*
* 字符串转换类名
*/
public static String convertClassName(String name) {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
}
public static boolean isEmpty(String s) {
return s == null || "".equals(s) || "null".equals(s);
}
public static String genWsshConnUniqueId(String httpSessionId, String webSocketSessionId) {
return String.format("%s#%s", httpSessionId, webSocketSessionId);
}
public static String genMcgWsConnUniqueId(String mcgWebScoketCode, String httpSessionId) {
return String.format("%s#%s", mcgWebScoketCode, httpSessionId);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.process.modules.mapper.SopDataSourceMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.SopDataSource">
<!--
WARNING - @mbg.generated
-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="db_type" jdbcType="VARCHAR" property="dbType" />
<result column="db_server" jdbcType="VARCHAR" property="dbServer" />
<result column="db_port" jdbcType="VARCHAR" property="dbPort" />
<result column="db_user_name" jdbcType="VARCHAR" property="dbUserName" />
<result column="db_pwd" jdbcType="VARCHAR" property="dbPwd" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="db_name" jdbcType="VARCHAR" property="dbName" />
</resultMap>
</mapper>
\ No newline at end of file \ No newline at end of file
...@@ -19,4 +19,22 @@ ...@@ -19,4 +19,22 @@
--> -->
grant_id, group_id, group_name, tpl_id, create_time, update_time, grant_status grant_id, group_id, group_name, tpl_id, create_time, update_time, grant_status
</sql> </sql>
<select id="countByTplId" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT group_id) FROM sop_tpl_grant WHERE tpl_id = #{tplId} AND grant_status != -1;
</select>
<select id="list" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sop_tpl_grant
where tpl_id = #{tplId} and grant_status != -1
</select>
<select id="countAllByTplId" resultType="java.lang.Integer">
SELECT COUNT(0) FROM sop_tpl_grant WHERE tpl_id = #{tplId}
</select>
<delete id="del">
update sop_tpl_grant set grant_status = -1 where grant_id = #{id}
</delete>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -27,4 +27,22 @@ ...@@ -27,4 +27,22 @@
--> -->
tpl_param_def, tpl_result_def tpl_param_def, tpl_result_def
</sql> </sql>
<select id="page" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sop_tpl
<where>
<if test="id != null and id !=''">
and tpl_id = #{id}
</if>
<if test="name != null and name !=''">
and tpl_name = #{name}
</if>
<if test="status != null">
and tpl_status = #{status}
</if>
</where>
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.cn.com.glsx; package cn.com.glsx.cn.com.glsx;
import cn.com.glsx.Application; import cn.com.glsx.Application;
import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.service.SopDataSourceService;
import cn.com.glsx.process.modules.service.UserDemoService; import cn.com.glsx.process.modules.service.UserDemoService;
import cn.com.glsx.process.plugin.dbconn.FlowDataAdapterImpl;
import cn.com.glsx.process.plugin.dbconn.McgBizAdapter;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/** /**
* 测试spring cloud 服务调用方式 * 测试spring cloud 服务调用方式
*/ */
...@@ -18,10 +26,16 @@ public class TestApplication { ...@@ -18,10 +26,16 @@ public class TestApplication {
@Autowired @Autowired
private UserDemoService userDemoService; private UserDemoService userDemoService;
@Test @Autowired
public void test() { private SopDataSourceService sopDataSourceService;
@Test
public void test() throws SQLException {
SopDataSource byId = sopDataSourceService.getById(1);
McgBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
List<Map<String, Object>> maps = mcgBizAdapter.tableQuery("SELECT * FROM sop_data_source");
System.out.println(maps);
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<property name="enableSubPackages" value="true" /> <property name="enableSubPackages" value="true" />
</javaClientGenerator> </javaClientGenerator>
<!-- 可配置多个 --> <!-- 可配置多个 -->
<table tableName="sop_tpl_node" domainObjectName="SopTplNode" enableSelectByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false"> <table tableName="sop_data_source" domainObjectName="SopDataSource" enableSelectByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false">
<generatedKey column="id" sqlStatement="MySql" identity="true"/> <generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table> </table>
<!--<table tableName="sop_tpl_node" domainObjectName="SopTplNode" enableSelectByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false"> <!--<table tableName="sop_tpl_node" domainObjectName="SopTplNode" enableSelectByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!