mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
add websockets suppor7
This commit is contained in:
@@ -72,15 +72,24 @@ def update_request_status(db: Session, request_id: int, status: RequestStatus) -
|
|||||||
db.refresh(db_request)
|
db.refresh(db_request)
|
||||||
return db_request
|
return db_request
|
||||||
|
|
||||||
def get_statistics(db: Session) -> Dict:
|
def get_statistics(db: Session) -> dict:
|
||||||
"""Get request statistics"""
|
"""Get requests statistics"""
|
||||||
total = db.query(func.count(Request.id)).scalar()
|
# Получаем общее количество заявок
|
||||||
by_status = dict(
|
total = db.query(Request).count()
|
||||||
db.query(
|
|
||||||
Request.status,
|
# Получаем количество заявок по статусам
|
||||||
func.count(Request.id)
|
status_counts = (
|
||||||
).group_by(Request.status).all()
|
db.query(Request.status, func.count(Request.id))
|
||||||
|
.group_by(Request.status)
|
||||||
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Формируем словарь статусов
|
||||||
|
by_status = {}
|
||||||
|
for status, count in status_counts:
|
||||||
|
by_status[status] = count
|
||||||
|
|
||||||
|
# Возвращаем статистику в нужном формате
|
||||||
return {
|
return {
|
||||||
"total": total,
|
"total": total,
|
||||||
"by_status": by_status
|
"by_status": by_status
|
||||||
|
@@ -27,15 +27,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="bg-white p-4 rounded-lg shadow">
|
<div class="bg-white p-4 rounded-lg shadow">
|
||||||
<div class="text-sm text-gray-500">Новые заявки</div>
|
<div class="text-sm text-gray-500">Новые заявки</div>
|
||||||
<div class="text-2xl font-semibold mt-1 text-blue-600">{{ statistics.by_status?.NEW || 0 }}</div>
|
<div class="text-2xl font-semibold mt-1 text-blue-600">{{ statistics.by_status?.new || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-white p-4 rounded-lg shadow">
|
<div class="bg-white p-4 rounded-lg shadow">
|
||||||
<div class="text-sm text-gray-500">В работе</div>
|
<div class="text-sm text-gray-500">В работе</div>
|
||||||
<div class="text-2xl font-semibold mt-1 text-yellow-600">{{ statistics.by_status?.IN_PROGRESS || 0 }}</div>
|
<div class="text-2xl font-semibold mt-1 text-yellow-600">{{ statistics.by_status?.in_progress || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-white p-4 rounded-lg shadow">
|
<div class="bg-white p-4 rounded-lg shadow">
|
||||||
<div class="text-sm text-gray-500">Завершенные</div>
|
<div class="text-sm text-gray-500">Завершенные</div>
|
||||||
<div class="text-2xl font-semibold mt-1 text-green-600">{{ statistics.by_status?.COMPLETED || 0 }}</div>
|
<div class="text-2xl font-semibold mt-1 text-green-600">{{ statistics.by_status?.completed || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, watch, onUnmounted } from 'vue';
|
import { ref, onMounted, onUnmounted, watch } from 'vue';
|
||||||
import axios from '@/plugins/axios';
|
import axios from '@/plugins/axios';
|
||||||
import { wsClient } from '@/plugins/websocket';
|
import { wsClient } from '@/plugins/websocket';
|
||||||
import VolumeChart from './charts/VolumeChart.vue';
|
import VolumeChart from './charts/VolumeChart.vue';
|
||||||
@@ -68,7 +68,11 @@ import StatusChart from './charts/StatusChart.vue';
|
|||||||
const period = ref('week');
|
const period = ref('week');
|
||||||
const statistics = ref({
|
const statistics = ref({
|
||||||
total: 0,
|
total: 0,
|
||||||
by_status: {}
|
by_status: {
|
||||||
|
new: 0,
|
||||||
|
in_progress: 0,
|
||||||
|
completed: 0
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const chartData = ref({
|
const chartData = ref({
|
||||||
volumeLabels: [],
|
volumeLabels: [],
|
||||||
@@ -96,7 +100,10 @@ const fetchStatistics = async () => {
|
|||||||
console.log('StatisticsPanel: Received statistics:', statsResponse.data);
|
console.log('StatisticsPanel: Received statistics:', statsResponse.data);
|
||||||
|
|
||||||
// Принудительно обновляем реактивное состояние
|
// Принудительно обновляем реактивное состояние
|
||||||
statistics.value = JSON.parse(JSON.stringify(statsResponse.data));
|
statistics.value = {
|
||||||
|
total: statsResponse.data.total,
|
||||||
|
by_status: statsResponse.data.by_status || {}
|
||||||
|
};
|
||||||
chartData.value = chartsResponse.data;
|
chartData.value = chartsResponse.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching statistics:', error);
|
console.error('Error fetching statistics:', error);
|
||||||
@@ -113,7 +120,10 @@ const handleWebSocketMessage = (data: any) => {
|
|||||||
console.log('StatisticsPanel: Updating statistics:', data.statistics);
|
console.log('StatisticsPanel: Updating statistics:', data.statistics);
|
||||||
|
|
||||||
// Принудительно обновляем реактивное состояние
|
// Принудительно обновляем реактивное состояние
|
||||||
statistics.value = JSON.parse(JSON.stringify(data.statistics));
|
statistics.value = {
|
||||||
|
total: data.statistics.total,
|
||||||
|
by_status: data.statistics.by_status || {}
|
||||||
|
};
|
||||||
|
|
||||||
console.log('StatisticsPanel: New statistics:', statistics.value);
|
console.log('StatisticsPanel: New statistics:', statistics.value);
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,10 @@ const fetchData = async () => {
|
|||||||
console.log('AdminDashboard: Received statistics:', statsResponse.data)
|
console.log('AdminDashboard: Received statistics:', statsResponse.data)
|
||||||
|
|
||||||
// Принудительно обновляем реактивное состояние
|
// Принудительно обновляем реактивное состояние
|
||||||
statistics.value = JSON.parse(JSON.stringify(statsResponse.data))
|
statistics.value = {
|
||||||
|
total: statsResponse.data.total,
|
||||||
|
by_status: statsResponse.data.by_status || {}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching data:', error)
|
console.error('Error fetching data:', error)
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,10 @@ const handleWebSocketMessage = (data: any) => {
|
|||||||
console.log('AdminDashboard: Updating statistics:', data.statistics)
|
console.log('AdminDashboard: Updating statistics:', data.statistics)
|
||||||
|
|
||||||
// Принудительно обновляем реактивное состояние
|
// Принудительно обновляем реактивное состояние
|
||||||
statistics.value = JSON.parse(JSON.stringify(data.statistics))
|
statistics.value = {
|
||||||
|
total: data.statistics.total,
|
||||||
|
by_status: data.statistics.by_status || {}
|
||||||
|
}
|
||||||
|
|
||||||
console.log('AdminDashboard: New statistics:', statistics.value)
|
console.log('AdminDashboard: New statistics:', statistics.value)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user