main
黄海 2 years ago
parent 17eb760ae1
commit 969337f209

@ -262,6 +262,13 @@
<artifactId>kafka-clients</artifactId>
<version>3.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/sharding-jdbc-core -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>

@ -62,7 +62,7 @@ public class ExamController extends Controller {
kv.set("list", list);
int allCount = 0;
for (Record record : list) {
allCount += record.getInt("count");
allCount += record.getInt("c");
}
kv.set("allCount", allCount);
renderJson(kv);

@ -28,8 +28,8 @@ public class ExamModel {
public Kv addPerson(String person_name, String ks, String tel) {
Kv kv = Kv.create();
//1、检查此人员是不是已经存在过
String sql = "select count(1) as count from t_exam_person where person_name=? and tel=? and b_use=1 and end_time is not null";
int cnt = Db.findFirst(sql, person_name, tel).getInt("count");
String sql = "select count(1) as c from t_exam_person where person_name=? and tel=? and b_use=1 and end_time is not null";
int cnt = Db.findFirst(sql, person_name, tel).getInt("c");
if (cnt > 0) {
kv.set("success", false);
kv.set("message", "当前人员已经进行过测试并且已交卷,不能重复进行!");
@ -71,8 +71,8 @@ public class ExamModel {
Collections.shuffle(tmpList);
//此题型需要抽取的数量
sql = "select count from t_exam_question_type where type_id=?";
int count = Db.findFirst(sql, type_id).getInt("count");
sql = "select \"count\" as c from t_exam_question_type where type_id=?";
int count = Db.findFirst(sql, type_id).getInt("c");
//批量存
List<Record> writeList = new ArrayList<>();
@ -153,7 +153,7 @@ public class ExamModel {
*
*/
public List<Record> getExamInfo() {
String sql = "select t1.type_id,t2.type_name,t2.count from t_exam_question as t1 inner join t_exam_question_type as t2 on t1.type_id=t2.type_id group by t1.type_id,t2.type_name,t2.count";
String sql = "select t1.type_id,t2.type_name,t2.\"count\" as c from t_exam_question as t1 inner join t_exam_question_type as t2 on t1.type_id=t2.type_id group by t1.type_id,t2.type_name,t2.\"count\"";
List<Record> list = Db.find(sql);
return list;
}
@ -255,11 +255,10 @@ public class ExamModel {
* ,
*/
public int getPersonUnFinishCount(String person_id) {
String sql = "select count(1) as count from t_exam_record where person_id=? and reply is null";
String sql = "select count(1) as \"count\" from t_exam_record where person_id=? and reply is null";
return Db.findFirst(sql, person_id).getInt("count");
}
/**
* ,()
*/

@ -0,0 +1,62 @@
package com.dsideal.FengHuang.Plugin;
import com.jfinal.plugin.IPlugin;
import com.jfinal.plugin.activerecord.IDataSourceProvider;
import com.jfinal.plugin.druid.DruidPlugin;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.shardingjdbc.api.MasterSlaveDataSourceFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
*
*/
public class SlaveDrudPlugin implements IPlugin, IDataSourceProvider {
//读写分离的rule
MasterSlaveRuleConfiguration masterSlaveRuleConfiguration;
//数据源map
Map<String, DruidPlugin> druidPlugins;
//原数据库连接源map
Map<String, DataSource> dataSourceMap;
//最终sharding-jdbc封装后的数据库连接源
DataSource dataSource;
public SlaveDrudPlugin(MasterSlaveRuleConfiguration masterSlaveRuleConfiguration, Map<String, DruidPlugin> druidPlugins) {
this.masterSlaveRuleConfiguration = masterSlaveRuleConfiguration;
this.druidPlugins = druidPlugins;
dataSourceMap = new HashMap<>();
}
public boolean start() {
//遍历数据源 将数据源加入sharding jdbc
for (Map.Entry<String, DruidPlugin> entry : druidPlugins.entrySet()) {
entry.getValue().start();
dataSourceMap.put(entry.getKey(), entry.getValue().getDataSource());
}
try {
dataSource =
MasterSlaveDataSourceFactory.createDataSource(dataSourceMap, masterSlaveRuleConfiguration,
new Properties());
System.out.println(dataSource);
} catch (SQLException e) {
e.printStackTrace();
}
return true;
}
public boolean stop() {
for (Map.Entry<String, DruidPlugin> entry : druidPlugins.entrySet()) {
entry.getValue().stop();
dataSourceMap.put(entry.getKey(), entry.getValue().getDataSource());
}
return true;
}
public DataSource getDataSource() {
return dataSource;
}
}

@ -13,6 +13,7 @@ import com.dsideal.FengHuang.Interceptor.*;
import com.dsideal.FengHuang.LoginPerson.Controller.LoginPersonController;
import com.dsideal.FengHuang.Menu.Controller.MenuController;
import com.dsideal.FengHuang.Organization.Controller.OrganizationController;
import com.dsideal.FengHuang.Plugin.SlaveDrudPlugin;
import com.dsideal.FengHuang.Student.Controller.StudentController;
import com.dsideal.FengHuang.StudentYd.Controller.StudentYdController;
import com.dsideal.FengHuang.Teacher.Controller.TeacherController;
@ -20,6 +21,7 @@ import com.dsideal.FengHuang.TeacherYd.Controller.TeacherYdController;
import com.dsideal.FengHuang.Util.FileUtil;
import com.dsideal.FengHuang.Util.LogBackLogFactory;
import com.dsideal.FengHuang.Util.PkUtil;
import com.google.common.collect.Lists;
import com.jfinal.config.*;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
@ -31,10 +33,14 @@ import com.jfinal.plugin.druid.IDruidStatViewAuth;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import org.apache.shardingsphere.api.config.masterslave.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class Start extends JFinalConfig {
@ -95,14 +101,12 @@ public class Start extends JFinalConfig {
}
/**
*
*/
@Override
public void configPlugin(Plugins me) {
DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
PropKit.get("password").trim(), PropKit.get("driverClassName"));
//最大连接池数量默认为8
/*
*/
public DruidPlugin createDruidPlugin(String url, String username, String password, String driverClass) {
DruidPlugin druidPlugin = new DruidPlugin(url, username, password, driverClass);
//最大连接池数量
druidPlugin.setMaxActive(20);
//最小连接池数量
druidPlugin.setMinIdle(1);
@ -114,7 +118,6 @@ public class Start extends JFinalConfig {
druidPlugin.setTimeBetweenEvictionRunsMillis(60000);
//连接保持空闲而不被驱逐的最小时间
druidPlugin.setMinEvictableIdleTimeMillis(300000);
//建议配置为true不影响性能并且保证安全性。申请连接的时候检测如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效。
druidPlugin.setTestWhileIdle(true);
//申请连接时执行validationQuery检测连接是否有效做了这个配置会降低性能。默认为true
@ -123,10 +126,38 @@ public class Start extends JFinalConfig {
druidPlugin.setTestOnReturn(false);
//数据监控
druidPlugin.addFilter(new StatFilter());
return druidPlugin;
}
/**
*
*/
@Override
public void configPlugin(Plugins me) {
DruidPlugin dp1 = createDruidPlugin(PropKit.get("master_jdbcUrl"), PropKit.get("master_user"), PropKit.get("master_password").trim(), PropKit.get("master_driverClassName"));
DruidPlugin dp2 = createDruidPlugin(PropKit.get("slave_jdbcUrl"), PropKit.get("slave_user"), PropKit.get("slave_password").trim(), PropKit.get("slave_driverClassName"));
Map<String, DruidPlugin> drudMap = new HashMap<>();
drudMap.put("ds_master", dp1);
drudMap.put("ds_slave", dp2);
//负载均衡算法
LoadBalanceStrategyConfiguration loadBalanceStrategyConfiguration = new LoadBalanceStrategyConfiguration("round_robin");
MasterSlaveRuleConfiguration masterSlaveRuleConfig =
new MasterSlaveRuleConfiguration(
"device_read_write",
"ds_master",
Lists.newArrayList("ds_slave"),
loadBalanceStrategyConfiguration);
SlaveDrudPlugin drudPlugin = new SlaveDrudPlugin(masterSlaveRuleConfig, drudMap);
me.add(drudPlugin);
ActiveRecordPlugin arp = new ActiveRecordPlugin("aGroup", drudPlugin);
arp.setDevMode(PropKit.getBoolean("devMode", false));
//配置数据库方言
arp.setDialect(new PostgreSqlDialect());
me.add(druidPlugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = Start.class.getClassLoader().getResource(".").getPath();
@ -142,8 +173,6 @@ public class Start extends JFinalConfig {
arp.setDialect(new PostgreSqlDialect());
//显示SQL语句
//arp.setShowSql(true);
//设置大小写不敏感工厂
//arp.setContainerFactory(new CaseInsensitiveContainerFactory(false));
//加载
me.add(arp);

@ -5,7 +5,7 @@
inner join t_exam_person as t2 on t1.person_id=t2.person_id
where t1.reply=t1.answer and t2.end_time is not null and t1.b_use=1 and t2.b_use=1
group by t1.person_id,t2.person_name,t2.ks,t2.tel,t2.start_time,t2.end_time
order by sum(t1.score) desc,EXTRACT(epoch FROM CAST( t2.end_time AS TIMESTAMP))-EXTRACT(epoch FROM CAST( t2.start_time AS TIMESTAMP)) asc
order by sum(t1.score) desc
#end
#sql("getPersonAllInfoAfterJiaoJuan")

@ -59,7 +59,7 @@
-- 获取指定父节点的行政区划
#sql("getAreaByParentId")
select t1.id,t1.area_code,t1.area_name,t1.parent_id,
(case when parent_id='-1' then 1 else 0 end ) as open,
if(parent_id='-1', 1 , 0 ) as open,
(select count(1) from t_dm_area as t2 where t2.parent_id=t1.id) as is_leaf
from t_dm_area as t1 where t1.parent_id=? order by t1.area_code
#end

@ -1,8 +1,13 @@
# 数据库信息
driverClassName=org.postgresql.Driver
user=postgres
password=DsideaL147258369
jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
master_driverClassName=org.postgresql.Driver
master_user=postgres
master_password=DsideaL147258369
master_jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
slave_driverClassName=org.postgresql.Driver
slave_user=postgres
slave_password=DsideaL147258369
slave_jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
# redis ip
redis_ip=10.10.14.169

@ -5,7 +5,7 @@
inner join t_exam_person as t2 on t1.person_id=t2.person_id
where t1.reply=t1.answer and t2.end_time is not null and t1.b_use=1 and t2.b_use=1
group by t1.person_id,t2.person_name,t2.ks,t2.tel,t2.start_time,t2.end_time
order by sum(t1.score) desc,EXTRACT(epoch FROM CAST( t2.end_time AS TIMESTAMP))-EXTRACT(epoch FROM CAST( t2.start_time AS TIMESTAMP)) asc
order by sum(t1.score) desc
#end
#sql("getPersonAllInfoAfterJiaoJuan")

@ -59,7 +59,7 @@
-- 获取指定父节点的行政区划
#sql("getAreaByParentId")
select t1.id,t1.area_code,t1.area_name,t1.parent_id,
(case when parent_id='-1' then 1 else 0 end ) as open,
if(parent_id='-1', 1 , 0 ) as open,
(select count(1) from t_dm_area as t2 where t2.parent_id=t1.id) as is_leaf
from t_dm_area as t1 where t1.parent_id=? order by t1.area_code
#end

@ -1,8 +1,13 @@
# 数据库信息
driverClassName=org.postgresql.Driver
user=postgres
password=DsideaL147258369
jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
master_driverClassName=org.postgresql.Driver
master_user=postgres
master_password=DsideaL147258369
master_jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
slave_driverClassName=org.postgresql.Driver
slave_user=postgres
slave_password=DsideaL147258369
slave_jdbcUrl=jdbc:postgresql://10.10.14.209:5432/ccdjzswd_db
# redis ip
redis_ip=10.10.14.169

Loading…
Cancel
Save