import repair
This commit is contained in:
@ -10,9 +10,9 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: org-ccalm-main
|
name: org-ccalm-main
|
||||||
datasource:
|
datasource:
|
||||||
#url: jdbc:postgresql://almaty.ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
url: jdbc:postgresql://10.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&connectTimeout=10000&socketTimeout=30000
|
||||||
#url: jdbc:postgresql://ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
#url: jdbc:postgresql://ccalm.org:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
||||||
url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
#url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000
|
||||||
username: postgres
|
username: postgres
|
||||||
password: 309A86FF65A78FB428F4E38DFE35F730
|
password: 309A86FF65A78FB428F4E38DFE35F730
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||||||
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import jakarta.servlet.ServletContext;
|
import jakarta.servlet.ServletContext;
|
||||||
|
import org.ccalm.main.models.ErrorResponseModel;
|
||||||
import org.ccalm.main.models.FrmLocustModel;
|
import org.ccalm.main.models.FrmLocustModel;
|
||||||
import org.ccalm.main.utils.CustomException;
|
import org.ccalm.main.utils.CustomException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -49,7 +50,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -62,8 +65,11 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import tctable.Tools;
|
import tctable.Tools;
|
||||||
import tools.DBTools;
|
import tools.DBTools;
|
||||||
|
import tools.Translation;
|
||||||
import tools.User;
|
import tools.User;
|
||||||
|
|
||||||
|
import static org.ccalm.main.Products.getHttpStatus;
|
||||||
|
|
||||||
//import com.google.common.io.CharStreams;
|
//import com.google.common.io.CharStreams;
|
||||||
|
|
||||||
//import jdk.nashorn.internal.parser.JSONParser;
|
//import jdk.nashorn.internal.parser.JSONParser;
|
||||||
@ -430,9 +436,18 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = {"/AcceptJSON_RUS", "/api/locust/v01/AcceptJSON_RUS"}, method = { RequestMethod.GET, RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = {"/AcceptJSON_RUS", "/api/locust/v01/AcceptJSON_RUS"}, method = { RequestMethod.GET, RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public String acceptCSV(@ModelAttribute User user, Model model,@RequestParam(required=false,name="file") MultipartFile file,@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip) {
|
public ResponseEntity<Object> acceptCSV(
|
||||||
JSONObject json = new JSONObject();
|
@ModelAttribute User user,
|
||||||
|
@RequestParam(required=false,name="file") MultipartFile file,
|
||||||
|
@RequestParam(required=false,name="skip",defaultValue = "0") Boolean skip,
|
||||||
|
@RequestParam(required=false,name="lng",defaultValue="1") String language_id
|
||||||
|
) {
|
||||||
|
Translation trt = new Translation(language_id,jdbcTemplate);
|
||||||
try{
|
try{
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("error_code",0);
|
||||||
|
json.put("error_message","");
|
||||||
|
|
||||||
//I select the maximum date, check that it is less than the current minus 2 days and try to load it
|
//I select the maximum date, check that it is less than the current minus 2 days and try to load it
|
||||||
LocalDate lastDate = null;
|
LocalDate lastDate = null;
|
||||||
String sql= """
|
String sql= """
|
||||||
@ -529,6 +544,8 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
|
|
||||||
if (!jsonObj.isNull("regionName") || jsonObj.getString("regionName").isEmpty()){
|
if (!jsonObj.isNull("regionName") || jsonObj.getString("regionName").isEmpty()){
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
sql= "select id from main.countriesregions where name ilike :regionName";
|
sql= "select id from main.countriesregions where name ilike :regionName";
|
||||||
parameters = new MapSqlParameterSource();
|
parameters = new MapSqlParameterSource();
|
||||||
parameters.addValue("regionName", "%" + jsonObj.getString("regionName") + "%");
|
parameters.addValue("regionName", "%" + jsonObj.getString("regionName") + "%");
|
||||||
@ -539,6 +556,10 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
locust.region_id = String.valueOf(rObj.getLong("id"));
|
locust.region_id = String.valueOf(rObj.getLong("id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if(!locust.region_id.isEmpty() && !jsonObj.isNull("townName")) {
|
if(!locust.region_id.isEmpty() && !jsonObj.isNull("townName")) {
|
||||||
|
|
||||||
@ -635,18 +656,27 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "select id from main.countriesdistricts where region_id=" + locust.region_id + " and name like '%" + locust.district + "%';";
|
try
|
||||||
parameters = new MapSqlParameterSource();
|
{
|
||||||
ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
sql = "select id from main.countriesdistricts where region_id=:region_id and name like :district;";
|
||||||
|
MapSqlParameterSource selectParameters = new MapSqlParameterSource();
|
||||||
|
selectParameters.addValue("region_id", locust.region_id, Types.INTEGER);
|
||||||
|
selectParameters.addValue("district", "%" + locust.district + "%", Types.VARCHAR);
|
||||||
|
ret = jdbcTemplate.query(sql, selectParameters, new DBTools.JsonRowMapper());
|
||||||
for (String s : ret) {
|
for (String s : ret) {
|
||||||
JSONObject rObj = new JSONObject(s);
|
JSONObject rObj = new JSONObject(s);
|
||||||
if (!rObj.isNull("id")) {
|
if (!rObj.isNull("id")) {
|
||||||
locust.district_id = String.valueOf(rObj.getLong("id"));
|
locust.district_id = String.valueOf(rObj.getLong("id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if(locust.district_id==null){
|
if(locust.district_id == null || locust.district_id.isEmpty()) System.out.println("Not find district = " + locust.district);
|
||||||
// throw new CustomException(200, 10000, "Not find district: "+locust.district,null,true);
|
|
||||||
//}
|
}catch (Exception ex)
|
||||||
|
{
|
||||||
|
//throw new CustomException(200, 10000, "Error select district = " + locust.district + " locust.region_id = "+locust.region_id,null,true);
|
||||||
|
System.out.println("Error select district = " + locust.district + " locust.region_id = "+locust.region_id);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
throw new CustomException(200, 10000, "Not find region: "+jsonObj.getString("regionName"),null,true);
|
throw new CustomException(200, 10000, "Not find region: "+jsonObj.getString("regionName"),null,true);
|
||||||
@ -865,10 +895,10 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
if(!jsonObjSub.isNull("phaseEvolutionName") && !jsonObjSub.optString("phaseEvolutionName","").isBlank()) {
|
if(!jsonObjSub.isNull("phaseEvolutionName") && !jsonObjSub.optString("phaseEvolutionName","").isBlank()) {
|
||||||
locust.phase = jsonObjSub.getString("phaseEvolutionName");
|
locust.phase = jsonObjSub.getString("phaseEvolutionName");
|
||||||
switch (jsonObjSub.optString("phaseEvolutionName",null).replace("'", "").trim()) {
|
switch (jsonObjSub.optString("phaseEvolutionName",null).replace("'", "").trim()) {
|
||||||
case "Кубышка":
|
case "Кубышка","Кокон":
|
||||||
locust.locust_have = "2"; //Кубышка = Яйца
|
locust.locust_have = "2"; //Кубышка = Яйца
|
||||||
break;
|
break;
|
||||||
case "Гусеница","Личинка","Личинка 2-го возраста","Личинка 3-го возраста","Личинка 4-го возраста","Личинка 5-го возраста":
|
case "Гусеница","Личинка","Личинка 2-го возраста","Личинка 3-го возраста","Личинка 4-го возраста","Личинка 5-го возраста","Особь":
|
||||||
locust.locust_have = "3";
|
locust.locust_have = "3";
|
||||||
break;
|
break;
|
||||||
case "Кулиги":
|
case "Кулиги":
|
||||||
@ -881,7 +911,9 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
throw new CustomException(200, 10000, "Not find phaseEvolutionName: (" + locust.phase+")", null, true);
|
throw new CustomException(200, 10000, "Not find phaseEvolutionName: (" + locust.phase+")", null, true);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
throw new CustomException(200, 10000, "Field phaseEvolutionName is null", null, true);
|
logger.warn(UUID.randomUUID().toString(), "Field phaseEvolutionName is null");
|
||||||
|
continue;
|
||||||
|
//throw new CustomException(200, 10000, "Field phaseEvolutionName is null", null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!jsonObjSub.isNull("subPestCount") && !jsonObjSub.optString("subPestCount","").isBlank()) {
|
if(!jsonObjSub.isNull("subPestCount") && !jsonObjSub.optString("subPestCount","").isBlank()) {
|
||||||
@ -1075,8 +1107,7 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
decodedString = Base64.getDecoder().decode(jsonObjIMG);
|
decodedString = Base64.getDecoder().decode(jsonObjIMG);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
model.addAttribute("PreviewTable", "Error decode");
|
throw new CustomException(200, 10000, "Error decode", null, true);
|
||||||
return "json";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decodedString != null) {
|
if (decodedString != null) {
|
||||||
@ -1148,19 +1179,18 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.addAttribute("PreviewTable","");
|
|
||||||
model.addAttribute("PreviewSQL","");
|
|
||||||
|
|
||||||
|
return new ResponseEntity<>(json.toString(), HttpStatus.OK);
|
||||||
} catch (CustomException e) {
|
} catch (CustomException e) {
|
||||||
if(e.isSaveToLog()) {
|
if(e.isSaveToLog()) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
logger.error(MarkerFactory.getMarker(e.getErrorMarker()), e.getMessage());
|
||||||
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
|
return new ResponseEntity<>(e.getErrorResponseModel(), getHttpStatus(e.getHttpCode()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage(), ex);
|
logger.error(MarkerFactory.getMarker(uuid), ex.getMessage());
|
||||||
|
return new ResponseEntity<>(new ErrorResponseModel(500, 10000, trt.trt(false, "Internal_Server_Error"), null, uuid), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
return json.toString();
|
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//https://127.0.0.1:8083/AcceptJSON_UZB
|
//https://127.0.0.1:8083/AcceptJSON_UZB
|
||||||
@ -1845,7 +1875,7 @@ public class AcceptJSON implements ServletContextAware {
|
|||||||
result.swarm_maturity = obj.optString("swarms_maturity",null); // boolean,
|
result.swarm_maturity = obj.optString("swarms_maturity",null); // boolean,
|
||||||
if(!obj.isNull("swarms_density") && !obj.optString("swarms_density","").isBlank()) {
|
if(!obj.isNull("swarms_density") && !obj.optString("swarms_density","").isBlank()) {
|
||||||
switch (obj.optString("swarms_density",null).replace("'", "").trim()) {
|
switch (obj.optString("swarms_density",null).replace("'", "").trim()) {
|
||||||
case "Low density", "Низкая", "Разреженная":
|
case "Low density", "Низкая", "Разреженная", "Плотность в стае ru":
|
||||||
result.swarm_density_id = "1";
|
result.swarm_density_id = "1";
|
||||||
result.swarm_density_uid = "d64bdd10-bf56-43a7-96b5-b9d22f36c19a";
|
result.swarm_density_uid = "d64bdd10-bf56-43a7-96b5-b9d22f36c19a";
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user