import repair

This commit is contained in:
2025-08-25 07:37:35 +05:00
parent 9f67439db3
commit 66b1f78745
2 changed files with 64 additions and 34 deletions

View File

@ -10,9 +10,9 @@ spring:
application:
name: org-ccalm-main
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://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
password: 309A86FF65A78FB428F4E38DFE35F730
driver-class-name: org.postgresql.Driver

View File

@ -35,6 +35,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.servlet.ServletContext;
import org.ccalm.main.models.ErrorResponseModel;
import org.ccalm.main.models.FrmLocustModel;
import org.ccalm.main.utils.CustomException;
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.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Controller;
@ -62,8 +65,11 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import tctable.Tools;
import tools.DBTools;
import tools.Translation;
import tools.User;
import static org.ccalm.main.Products.getHttpStatus;
//import com.google.common.io.CharStreams;
//import jdk.nashorn.internal.parser.JSONParser;
@ -430,9 +436,18 @@ public class AcceptJSON implements ServletContextAware {
* @return
*/
@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) {
JSONObject json = new JSONObject();
public ResponseEntity<Object> acceptCSV(
@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{
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
LocalDate lastDate = null;
String sql= """
@ -529,6 +544,8 @@ public class AcceptJSON implements ServletContextAware {
if (!jsonObj.isNull("regionName") || jsonObj.getString("regionName").isEmpty()){
try
{
sql= "select id from main.countriesregions where name ilike :regionName";
parameters = new MapSqlParameterSource();
parameters.addValue("regionName", "%" + jsonObj.getString("regionName") + "%");
@ -539,6 +556,10 @@ public class AcceptJSON implements ServletContextAware {
locust.region_id = String.valueOf(rObj.getLong("id"));
}
}
}catch (Exception ex)
{
ex.printStackTrace();
}
if(!locust.region_id.isEmpty() && !jsonObj.isNull("townName")) {
@ -635,18 +656,27 @@ public class AcceptJSON implements ServletContextAware {
}break;
}
sql = "select id from main.countriesdistricts where region_id=" + locust.region_id + " and name like '%" + locust.district + "%';";
parameters = new MapSqlParameterSource();
ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
try
{
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) {
JSONObject rObj = new JSONObject(s);
if (!rObj.isNull("id")) {
locust.district_id = String.valueOf(rObj.getLong("id"));
}
}
//if(locust.district_id==null){
// throw new CustomException(200, 10000, "Not find district: "+locust.district,null,true);
//}
if(locust.district_id == null || locust.district_id.isEmpty()) System.out.println("Not find district = " + locust.district);
}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{
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()) {
locust.phase = jsonObjSub.getString("phaseEvolutionName");
switch (jsonObjSub.optString("phaseEvolutionName",null).replace("'", "").trim()) {
case "Кубышка":
case "Кубышка","Кокон":
locust.locust_have = "2"; //Кубышка = Яйца
break;
case "Гусеница","Личинка","Личинка 2-го возраста","Личинка 3-го возраста","Личинка 4-го возраста","Личинка 5-го возраста":
case "Гусеница","Личинка","Личинка 2-го возраста","Личинка 3-го возраста","Личинка 4-го возраста","Личинка 5-го возраста","Особь":
locust.locust_have = "3";
break;
case "Кулиги":
@ -881,7 +911,9 @@ public class AcceptJSON implements ServletContextAware {
throw new CustomException(200, 10000, "Not find phaseEvolutionName: (" + locust.phase+")", null, true);
}
}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()) {
@ -1075,8 +1107,7 @@ public class AcceptJSON implements ServletContextAware {
decodedString = Base64.getDecoder().decode(jsonObjIMG);
} catch (Exception e) {
e.printStackTrace();
model.addAttribute("PreviewTable", "Error decode");
return "json";
throw new CustomException(200, 10000, "Error decode", null, true);
}
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) {
if(e.isSaveToLog()) {
String uuid = UUID.randomUUID().toString();
logger.error(MarkerFactory.getMarker(uuid), e.getMessage(), e);
logger.error(MarkerFactory.getMarker(e.getErrorMarker()), e.getMessage());
}
return new ResponseEntity<>(e.getErrorResponseModel(), getHttpStatus(e.getHttpCode()));
} catch (Exception ex) {
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
@ -1845,7 +1875,7 @@ public class AcceptJSON implements ServletContextAware {
result.swarm_maturity = obj.optString("swarms_maturity",null); // boolean,
if(!obj.isNull("swarms_density") && !obj.optString("swarms_density","").isBlank()) {
switch (obj.optString("swarms_density",null).replace("'", "").trim()) {
case "Low density", "Низкая", "Разреженная":
case "Low density", "Низкая", "Разреженная", "Плотность в стае ru":
result.swarm_density_id = "1";
result.swarm_density_uid = "d64bdd10-bf56-43a7-96b5-b9d22f36c19a";
break;