Compare commits

...

50 Commits

Author SHA1 Message Date
0584a39989 Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:42:23 +00:00
f05ea61703 Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:31:15 +00:00
aff58ed540 Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:28:23 +00:00
dd284cfdd1 Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:26:01 +00:00
46f1af6120 Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:17:42 +00:00
e575a33e0e Обновить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 06:01:49 +00:00
34e6504871 Добавить pom.xml 2025-09-12 05:48:14 +00:00
5c88b9f534 Добавить src/main/java/org/lanit/service/JsonProcessingService.java 2025-09-12 05:47:34 +00:00
56dca69f93 Добавить src/main/java/org/lanit/models/Ticker.java 2025-09-12 05:46:22 +00:00
6c182d4e7c Добавить src/main/java/org/lanit/models/Response.java 2025-09-12 05:46:07 +00:00
4b19a73fd7 Добавить src/main/java/org/lanit/models/Info.java 2025-09-12 05:45:53 +00:00
d92e327d60 Добавить src/main/java/org/lanit/models/ErrorResponse.java 2025-09-12 05:45:38 +00:00
058b7e45fa Добавить src/main/java/org/lanit/models/DeleteRequest.java 2025-09-12 05:45:07 +00:00
32ea0c3966 Добавить src/main/java/org/lanit/models/Delete.java 2025-09-12 05:44:50 +00:00
356dc79556 Добавить src/main/java/org/lanit/models/Alert.java 2025-09-12 05:44:35 +00:00
93acd2eff9 Добавить src/main/java/org/lanit/models/AddRequest.java 2025-09-12 05:44:20 +00:00
e7ba782ad2 Добавить src/main/java/org/lanit/models/Add.java 2025-09-12 05:43:53 +00:00
387551bd7b Добавить src/main/java/org/lanit/controllers/JSONController.java 2025-09-12 05:43:20 +00:00
0bd4a82fa2 Добавить src/main/java/org/lanit/Application.java 2025-09-12 05:42:26 +00:00
f7f66d2253 Удалить mathmodenjoyer.jmx 2025-09-12 05:40:05 +00:00
015eda4264 Загрузить файлы в «/» 2025-07-21 17:54:18 +00:00
5c4840389d Загрузить файлы в «/» 2025-07-21 17:50:05 +00:00
ffdcbf9cf2 Загрузить файлы в «/» 2025-07-21 17:40:54 +00:00
b58f7035f1 Загрузить файлы в «/» 2025-07-21 17:28:11 +00:00
d71fae29e7 Загрузить файлы в «/» 2025-07-21 16:31:51 +00:00
50861b6caf Удалить mathmodenjoyer.jmx 2025-07-21 16:31:42 +00:00
16c1822a0e Загрузить файлы в «/» 2025-07-21 13:44:54 +00:00
ea1b497c93 Загрузить файлы в «/» 2025-07-21 10:20:09 +00:00
5c8ca7874f Удалить mathmodenjoyer.jmx 2025-07-21 10:19:53 +00:00
543f9aa46b Загрузить файлы в «/» 2025-07-21 09:55:04 +00:00
84bfb6c650 Загрузить файлы в «/» 2025-07-20 22:40:04 +00:00
102f1e6cdd Загрузить файлы в «/» 2025-07-20 22:36:22 +00:00
4add0bdebb Удалить mathmodenjoyer.jmx 2025-07-20 22:36:07 +00:00
a045440b93 Загрузить файлы в «/» 2025-07-20 22:16:54 +00:00
00181d738f Удалить mathmodenjoyer.jmx 2025-07-20 22:16:27 +00:00
488bc06cab Загрузить файлы в «/» 2025-07-20 21:59:34 +00:00
46bc2115c1 Удалить mathmodenjoyer.jmx 2025-07-20 21:59:25 +00:00
17710475d3 Загрузить файлы в «/» 2025-07-20 21:55:27 +00:00
5061d3bdd8 Удалить mathmodenjoyer.jmx 2025-07-20 21:55:15 +00:00
ebf9130372 Загрузить файлы в «/» 2025-07-20 17:19:54 +00:00
974458477f Удалить mathmodenjoyer.jmx 2025-07-20 17:19:42 +00:00
f143194275 Загрузить файлы в «/» 2025-07-20 16:27:28 +00:00
86dbc99f89 Удалить mathmodenjoyer.jmx 2025-07-20 16:27:19 +00:00
c2f3531e07 Загрузить файлы в «/» 2025-07-20 16:22:06 +00:00
4f146aae62 Удалить mathmodenjoyer.jmx 2025-07-20 16:21:33 +00:00
c6fdd57d51 Обновить mathmodenjoyer.jmx 2025-07-19 20:54:50 +00:00
7544c614ab Загрузить файлы в «/» 2025-07-19 20:54:06 +00:00
8e98abdda4 Удалить last_friday_datetime.py 2025-07-19 20:53:48 +00:00
62917a9589 Удалить count_sum_pandas.py 2025-07-19 20:53:46 +00:00
40a8fb8d4c Удалить comparison.py 2025-07-19 20:53:43 +00:00
16 changed files with 363 additions and 23 deletions

View File

@ -1,7 +0,0 @@
def compare(a: str) -> bool:
for i in range(len(a)):
if(a[i].isdigit() == False):
if a[i] == "<":
return int(a[:i]) < int(a[i + 1:])
elif (a[i] == ">"):
return int(a[:i]) > int(a[i + 1:])

View File

@ -1,4 +0,0 @@
import pandas as pd
def count_sum(df: pd.DataFrame) -> pd.DataFrame:
return df.groupby('Товар')['Количество'].sum().reset_index().set_index('Товар')

View File

@ -1,12 +0,0 @@
from datetime import datetime, timedelta
def get_last_friday(a: str) -> str:
date = datetime.strptime(a, "%m/%Y").date()
next_month = date.replace(day=28) + timedelta(days=7)
last_day = next_month - timedelta(days=next_month.day)
# Идем назад до пятницы
while last_day.weekday() != 4:
last_day -= timedelta(days=1)
return last_day.strftime("%d.%m.%Y")

20
pom.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version> <!-- Стабильная версия для Java 8 -->
</parent>
<groupId>org.lanit</groupId>
<artifactId>json-stub</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,11 @@
package org.lanit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,93 @@
package org.lanit.controllers;
import org.lanit.models.*;
import org.lanit.service.JsonProcessingService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.time.Instant;
@Controller
public class JSONController {
private final JsonProcessingService processingService;
private final ObjectMapper objectMapper;
public JSONController(JsonProcessingService processingService, ObjectMapper objectMapper) {
this.processingService = processingService;
this.objectMapper = objectMapper;
}
//Метод для создания JSON ответов с чистым Content-Type
private ResponseEntity<Object> createJsonResponse(Object body, HttpStatus status) {
return ResponseEntity.status(status)
.header("Content-Type", "application/json")
.body(body);
}
/**
* Основной endpoint для обработки JSON запросов
* @ResponseBody указывает, что возвращаемое значение должно быть записано в тело ответа
*/
@PostMapping(value = "/json", produces = "application/json", consumes = "application/json")
@ResponseBody
public ResponseEntity<?> handleJsonRequest(
@RequestParam("action") String action,
@RequestBody String jsonBody) throws IOException {
try {
// Обработка действий ADD и DELETE
if ("add".equals(action)) {
AddRequest addRequest = objectMapper.readValue(jsonBody, AddRequest.class);
Info modifiedInfo = processingService.processAdd(addRequest);
Response response = new Response();
response.setInfo(modifiedInfo);
response.setUuid(addRequest.getUuid()); // Сохраняем исходный UUID
response.setLastUpdate(Instant.now().toString()); // Обновляем время ответа
return createJsonResponse(response, HttpStatus.OK);
} else if ("delete".equals(action)) {
DeleteRequest deleteRequest = objectMapper.readValue(jsonBody, DeleteRequest.class);
Info modifiedInfo = processingService.processDelete(deleteRequest);
Response response = new Response();
response.setInfo(modifiedInfo);
response.setUuid(deleteRequest.getUuid());
response.setLastUpdate(Instant.now().toString());
return createJsonResponse(response, HttpStatus.OK);
} else {
// Обработка неизвестных действий
ErrorResponse error = new ErrorResponse();
error.setStatus("error");
error.setMessage("Передан некорректный action - " + action);
return createJsonResponse(error, HttpStatus.BAD_REQUEST);
}
} catch (RuntimeException e) {
ErrorResponse error = new ErrorResponse();
error.setStatus("error");
error.setMessage(e.getMessage());
// Определяем HTTP статус на основе текста ошибки
HttpStatus status = e.getMessage().contains("тикер") || e.getMessage().contains("индекс")
? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST;
return createJsonResponse(error, status);
} catch (IOException e) {
// Обработка ошибок парсинга JSON
ErrorResponse error = new ErrorResponse();
error.setStatus("error");
error.setMessage("Ошибка разбора JSON");
return createJsonResponse(error, HttpStatus.BAD_REQUEST);
}
}
}

View File

@ -0,0 +1,21 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Add {
@JsonProperty("name")
private String name;
@JsonProperty("timeFrame")
private int timeFrame;
@JsonProperty("percent")
private int percent;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getTimeFrame() { return timeFrame; }
public void setTimeFrame(int timeFrame) { this.timeFrame = timeFrame; }
public int getPercent() { return percent; }
public void setPercent(int percent) { this.percent = percent; }
}

View File

@ -0,0 +1,26 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class AddRequest {
@JsonProperty("info")
private Info info;
@JsonProperty("add")
private Add add;
@JsonProperty("uuid")
private String uuid;
@JsonProperty("lastUpdate")
private String lastUpdate;
public Info getInfo() { return info; }
public void setInfo(Info info) { this.info = info; }
public Add getAdd() { return add; }
public void setAdd(Add add) { this.add = add; }
public String getUuid() { return uuid; }
public void setUuid(String uuid) { this.uuid = uuid; }
public String getLastUpdate() { return lastUpdate; }
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
}

View File

@ -0,0 +1,16 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Alert {
@JsonProperty("timeFrame")
private int timeFrame;
@JsonProperty("percent")
private int percent;
public int getTimeFrame() { return timeFrame; }
public void setTimeFrame(int timeFrame) { this.timeFrame = timeFrame; }
public int getPercent() { return percent; }
public void setPercent(int percent) { this.percent = percent; }
}

View File

@ -0,0 +1,16 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Delete {
@JsonProperty("tickerName")
private String tickerName;
@JsonProperty("alertIndex")
private int alertIndex;
public String getTickerName() { return tickerName; }
public void setTickerName(String tickerName) { this.tickerName = tickerName; }
public int getAlertIndex() { return alertIndex; }
public void setAlertIndex(int alertIndex) { this.alertIndex = alertIndex; }
}

View File

@ -0,0 +1,26 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class DeleteRequest {
@JsonProperty("info")
private Info info;
@JsonProperty("delete")
private Delete delete;
@JsonProperty("uuid")
private String uuid;
@JsonProperty("lastUpdate")
private String lastUpdate;
public Info getInfo() { return info; }
public void setInfo(Info info) { this.info = info; }
public Delete getDelete() { return delete; }
public void setDelete(Delete delete) { this.delete = delete; }
public String getUuid() { return uuid; }
public void setUuid(String uuid) { this.uuid = uuid; }
public String getLastUpdate() { return lastUpdate; }
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
}

View File

@ -0,0 +1,16 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ErrorResponse {
@JsonProperty("status")
private String status;
@JsonProperty("message")
private String message;
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
}

View File

@ -0,0 +1,17 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Info {
@JsonProperty("userID")
private String userID;
@JsonProperty("tickers")
private List<Ticker> tickers;
public String getUserID() { return userID; }
public void setUserID(String userID) { this.userID = userID; }
public List<Ticker> getTickers() { return tickers; }
public void setTickers(List<Ticker> tickers) { this.tickers = tickers; }
}

View File

@ -0,0 +1,21 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Response {
@JsonProperty("info")
private Info info;
@JsonProperty("uuid")
private String uuid;
@JsonProperty("lastUpdate")
private String lastUpdate;
public Info getInfo() { return info; }
public void setInfo(Info info) { this.info = info; }
public String getUuid() { return uuid; }
public void setUuid(String uuid) { this.uuid = uuid; }
public String getLastUpdate() { return lastUpdate; }
public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; }
}

View File

@ -0,0 +1,17 @@
package org.lanit.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Ticker {
@JsonProperty("ticker")
private String ticker;
@JsonProperty("alerts")
private List<Alert> alerts;
public String getTicker() { return ticker; }
public void setTicker(String ticker) { this.ticker = ticker; }
public List<Alert> getAlerts() { return alerts; }
public void setAlerts(List<Alert> alerts) { this.alerts = alerts; }
}

View File

@ -0,0 +1,63 @@
package org.lanit.service;
import org.lanit.models.*;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class JsonProcessingService {
public Info processAdd(AddRequest request) {
Info info = request.getInfo();
Add add = request.getAdd();
List<Ticker> tickers = info.getTickers();
// Ищем тикер
Optional<Ticker> existingTicker = tickers.stream()
.filter(t -> t.getTicker().equals(add.getName()))
.findFirst();
Ticker targetTicker;
if (existingTicker.isPresent()) {
targetTicker = existingTicker.get();
} else {
// Создаем новый тикер
targetTicker = new Ticker();
targetTicker.setTicker(add.getName());
targetTicker.setAlerts(new java.util.ArrayList<>());
tickers.add(targetTicker);
}
// Создаем и добавляем оповещение
Alert newAlert = new Alert();
newAlert.setTimeFrame(add.getTimeFrame());
newAlert.setPercent(add.getPercent());
targetTicker.getAlerts().add(newAlert);
return info;
}
public Info processDelete(DeleteRequest request) {
Info info = request.getInfo();
Delete delete = request.getDelete();
List<Ticker> tickers = info.getTickers();
// Ищем тикер
Ticker targetTicker = tickers.stream()
.filter(t -> t.getTicker().equals(delete.getTickerName()))
.findFirst()
.orElseThrow(() -> new RuntimeException("Передан некорректный тикер"));
// Проверяем индекс
List<Alert> alerts = targetTicker.getAlerts();
int index = delete.getAlertIndex();
if (index < 0 || index >= alerts.size()) {
throw new RuntimeException("Передан некорректный индекс");
}
// Удаляем оповещение
alerts.remove(index);
return info;
}
}