|
@@ -35,9 +35,9 @@ public class DataUtil {
|
|
|
|
|
|
String sql;
|
|
String sql;
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
- sql = getOracleSql(dataType, false);
|
|
|
|
|
|
+ sql = getOracleSql(null, null, dataType, false);
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
- sql = getMysqlSql(dataType, false);
|
|
|
|
|
|
+ sql = getMysqlSql(dataType, false, null, null);
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
}
|
|
}
|
|
@@ -47,10 +47,10 @@ public class DataUtil {
|
|
public List<UserDataVo> listUser(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
public List<UserDataVo> listUser(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
String sql;
|
|
String sql;
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
- sql = getOracleSql(dataType, true, "code");
|
|
|
|
|
|
+ sql = getOracleSql(null, null, dataType, true, "code");
|
|
return pageOracle(jdbcTemplate, sql, UserDataVo.class);
|
|
return pageOracle(jdbcTemplate, sql, UserDataVo.class);
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
- sql = getMysqlSql(dataType, true);
|
|
|
|
|
|
+ sql = getMysqlSql(dataType, true, null, null);
|
|
return pageMysql(jdbcTemplate, sql, UserDataVo.class);
|
|
return pageMysql(jdbcTemplate, sql, UserDataVo.class);
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
@@ -60,9 +60,9 @@ public class DataUtil {
|
|
public List<CourseDataVo> listCourse(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
public List<CourseDataVo> listCourse(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
String sql;
|
|
String sql;
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
- sql = getOracleSql(dataType, false);
|
|
|
|
|
|
+ sql = getOracleSql(null, null, dataType, false);
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
- sql = getMysqlSql(dataType, false);
|
|
|
|
|
|
+ sql = getMysqlSql(dataType, false, null, null);
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
}
|
|
}
|
|
@@ -72,22 +72,22 @@ public class DataUtil {
|
|
public List<ExamTaskDataVo> listExamTask(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
public List<ExamTaskDataVo> listExamTask(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
String sql;
|
|
String sql;
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
- sql = getOracleSql(dataType, false);
|
|
|
|
|
|
+ sql = getOracleSql(null, null, dataType, false);
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
- sql = getMysqlSql(dataType, false);
|
|
|
|
|
|
+ sql = getMysqlSql(dataType, false, null, null);
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
}
|
|
}
|
|
return query(jdbcTemplate, sql, ExamTaskDataVo.class);
|
|
return query(jdbcTemplate, sql, ExamTaskDataVo.class);
|
|
}
|
|
}
|
|
|
|
|
|
- public List<TSyncDataStudent> listExamStudent(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
|
|
+ public List<TSyncDataStudent> listExamStudent(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType, String xn, String xq) {
|
|
String sql;
|
|
String sql;
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
if ("ORACLE".equals(datasourceType.trim())) {
|
|
- sql = getOracleSql(dataType, true, "coursecode", "studentcode");
|
|
|
|
|
|
+ sql = getOracleSql(xn, xq, dataType, true, "coursecode", "studentcode");
|
|
return pageOracle(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
return pageOracle(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
} else if ("MYSQL".equals(datasourceType.trim())) {
|
|
- sql = getMysqlSql(dataType, true);
|
|
|
|
|
|
+ sql = getMysqlSql(dataType, true, xn, xq);
|
|
return pageMysql(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
return pageMysql(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
@@ -160,18 +160,35 @@ public class DataUtil {
|
|
return listAll;
|
|
return listAll;
|
|
}
|
|
}
|
|
|
|
|
|
- private String getMysqlSql(DataType dataType, boolean isPage) {
|
|
|
|
|
|
+ private String getMysqlSql(DataType dataType, boolean isPage, String xn, String xq) {
|
|
//sql语句
|
|
//sql语句
|
|
- String sql;
|
|
|
|
|
|
+ StringJoiner sql = new StringJoiner("");
|
|
if (isPage) {
|
|
if (isPage) {
|
|
- sql = "select * from " + dataType.getTable() + " limit ? ?";
|
|
|
|
|
|
+ sql.add("select * from ");
|
|
|
|
+ sql.add(dataType.getTable());
|
|
|
|
+ sql.add(" where 1=1 ");
|
|
|
|
+ if (StringUtils.isNotBlank(xn)) {
|
|
|
|
+ sql.add(" and xnm = \'" + xn + "\'");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(xq)) {
|
|
|
|
+ sql.add(" and xqm = \'" + xq + "\'");
|
|
|
|
+ }
|
|
|
|
+ sql.add(" limit ? ?");
|
|
} else {
|
|
} else {
|
|
- sql = "select * from " + dataType.getTable();
|
|
|
|
|
|
+ sql.add("select * from ");
|
|
|
|
+ sql.add(dataType.getTable());
|
|
|
|
+ sql.add(" where 1=1 ");
|
|
|
|
+ if (StringUtils.isNotBlank(xn)) {
|
|
|
|
+ sql.add(" and xnm = \'" + xn + "\'");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(xq)) {
|
|
|
|
+ sql.add(" and xqm = \'" + xq + "\'");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return sql;
|
|
|
|
|
|
+ return sql.toString();
|
|
}
|
|
}
|
|
|
|
|
|
- private String getOracleSql(DataType dataType, boolean isPage, String... sortColumn) {
|
|
|
|
|
|
+ private String getOracleSql(String xn, String xq, DataType dataType, boolean isPage, String... sortColumn) {
|
|
//sql语句
|
|
//sql语句
|
|
String sql;
|
|
String sql;
|
|
if (isPage) {
|
|
if (isPage) {
|
|
@@ -184,15 +201,42 @@ public class DataUtil {
|
|
stringJoiner.add(sortStr.toString());
|
|
stringJoiner.add(sortStr.toString());
|
|
stringJoiner.add(") AS rn FROM ");
|
|
stringJoiner.add(") AS rn FROM ");
|
|
stringJoiner.add("\"" + dataType.getTable() + "\"");
|
|
stringJoiner.add("\"" + dataType.getTable() + "\"");
|
|
- stringJoiner.add(" t) WHERE rn BETWEEN ? AND ?");
|
|
|
|
|
|
+ stringJoiner.add(" t where 1=1 ");
|
|
|
|
+ if (StringUtils.isNotBlank(xn)) {
|
|
|
|
+ stringJoiner.add(" and xnm = \'" + xn + "\'");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(xq)) {
|
|
|
|
+ stringJoiner.add(" and xqm = \'" + xq + "\'");
|
|
|
|
+ }
|
|
|
|
+ stringJoiner.add(" ) WHERE rn BETWEEN ? AND ?");
|
|
sql = stringJoiner.toString();
|
|
sql = stringJoiner.toString();
|
|
} else {
|
|
} else {
|
|
- sql = "select * from \"" + dataType.getTable() + "\"";
|
|
|
|
|
|
+ sql = "select * from \"" + dataType.getTable() + "\" where 1=1 ";
|
|
|
|
+ if (StringUtils.isNotBlank(xn)) {
|
|
|
|
+ sql += " and xnm = \'" + xn + "\'";
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(xq)) {
|
|
|
|
+ sql += " and xqm = \'" + xq + "\'";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
log.info(dataType.getName() + "数据同步sql:" + sql);
|
|
log.info(dataType.getName() + "数据同步sql:" + sql);
|
|
return sql;
|
|
return sql;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ DataUtil dataUtil = new DataUtil();
|
|
|
|
+ System.out.println(dataUtil.getOracleSql(null, null, DataType.B, true, "semestercode"));
|
|
|
|
+ System.out.println(dataUtil.getOracleSql(null, null, DataType.B, false, "semestercode", "examname"));
|
|
|
|
+ System.out.println(dataUtil.getOracleSql("2023-2024", "1", DataType.B, true, "semestercode"));
|
|
|
|
+ System.out.println(dataUtil.getOracleSql("2023-2024", "", DataType.B, false, "semestercode"));
|
|
|
|
+ System.out.println("------------------------------------");
|
|
|
|
+ System.out.println(dataUtil.getMysqlSql(DataType.B, true, null, null));
|
|
|
|
+ System.out.println(dataUtil.getMysqlSql(DataType.B, false, null, null));
|
|
|
|
+ System.out.println(dataUtil.getMysqlSql(DataType.B, true, "2023-2024", "1"));
|
|
|
|
+ System.out.println(dataUtil.getMysqlSql(DataType.B, false, "2023-2024", ""));
|
|
|
|
+ }
|
|
|
|
+
|
|
public DataSource createDataSourceMap(Long schoolId) {
|
|
public DataSource createDataSourceMap(Long schoolId) {
|
|
SysConfig datasourceType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_TYPE);
|
|
SysConfig datasourceType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_TYPE);
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getConfigValue())) {
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getConfigValue())) {
|