Объединение
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
package tools;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.sql.*;
|
||||
//import tools.dbtools.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Translation {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Translation.class);
|
||||
|
||||
public int language_id;
|
||||
//public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
public Connection conn;
|
||||
public Translation(String lng, Connection conn){
|
||||
public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
public Translation(String lng, NamedParameterJdbcTemplate jdbcTemplate){
|
||||
language_id=1;
|
||||
switch (lng) {
|
||||
case "kz":
|
||||
@ -29,12 +29,10 @@ public class Translation {
|
||||
language_id = 1;
|
||||
break;
|
||||
}
|
||||
this.conn = conn;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public String trt(String text){
|
||||
|
||||
boolean find = false;
|
||||
String sql = """
|
||||
select
|
||||
translation
|
||||
@ -42,39 +40,19 @@ public class Translation {
|
||||
main._translations
|
||||
where
|
||||
del=false
|
||||
and language_id=${language_id}
|
||||
and identifier=${identifier};
|
||||
and language_id=:language_id
|
||||
and identifier=:identifier;
|
||||
""";
|
||||
|
||||
PreparedStatementNamed stmtn=null;
|
||||
try {
|
||||
stmtn = new PreparedStatementNamed(conn, sql);
|
||||
stmtn.setInt("language_id", language_id);
|
||||
stmtn.setString("identifier", text);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(stmtn!=null){
|
||||
PreparedStatement stmt=stmtn.getPreparedStatement();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
text = rs.getString(1);
|
||||
find = true;
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("language_id", language_id);
|
||||
parameters.addValue("identifier", text);
|
||||
List<String> ret = jdbcTemplate.query(sql, parameters, new tools.DBTools.JsonRowMapper());
|
||||
int i = 0;
|
||||
for (i = 0; i < ret.size(); i++) {
|
||||
JSONObject json = new JSONObject(ret.get(i));
|
||||
text = json.getString("translation");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try { if (rs != null) rs.close(); } catch (Exception e) {};
|
||||
try { if (stmt != null) stmt.close(); } catch (Exception e) {};
|
||||
}
|
||||
}
|
||||
|
||||
if(!find){
|
||||
if(i==0){
|
||||
text = text.replace("_", " ");
|
||||
}
|
||||
return text;
|
||||
|
||||
Reference in New Issue
Block a user