diff --git a/back/api/settings.py b/back/api/settings.py index 13e2417..e4b71f1 100644 --- a/back/api/settings.py +++ b/back/api/settings.py @@ -39,6 +39,7 @@ ALLOWED_HOSTS = [ CORS_ALLOWED_ORIGINS = [ "http://localhost", "http://localhost:3000", + "http://localhost:3001", "http://192.168.106.234:3000", "https://toinv.svs-tech.pro", ] diff --git a/back/tgbot/serializers.py b/back/tgbot/serializers.py index 10d9d40..dfcbbd4 100644 --- a/back/tgbot/serializers.py +++ b/back/tgbot/serializers.py @@ -29,13 +29,19 @@ class TgItemSerializer(serializers.ModelSerializer): class TgStatItemSerializer(serializers.Serializer): - location = serializers.SerializerMethodField() + location = serializers.SerializerMethodField(required=False) inv_count = serializers.IntegerField() tmc = serializers.SerializerMethodField() def get_location(self, obj): - queryset = Territory.objects.get(id=obj.get("location__parent")) - serializer = TerritorySerializer(queryset) + if not obj.get("location__parent"): + return None + if isinstance(obj.get("location__parent"), list): + queryset = Territory.objects.filter(id__in=obj.get("location__parent")) + serializer = TerritorySerializer(queryset, many=True) + else: + queryset = Territory.objects.get(id=obj.get("location__parent")) + serializer = TerritorySerializer(queryset) return serializer.data @@ -45,7 +51,6 @@ class TgStatItemSerializer(serializers.Serializer): .values("tmc__name") .annotate(count=Count("id")) ) - logger.info(queryset) serializer = TmcElementSerializer(queryset, many=True) return serializer.data diff --git a/back/tgbot/views.py b/back/tgbot/views.py index be94921..7445707 100644 --- a/back/tgbot/views.py +++ b/back/tgbot/views.py @@ -129,17 +129,31 @@ class TmcStatViewset(viewsets.ViewSet): http_method_names = ["get"] def list(self, request): - queryset = ( - TgItem.objects.all() - .values("location__parent") - .annotate( - inv_count=Count("location__parent"), - tmc_count=Count("tmc__tmc_id", distinct=True) + if 'type' in request.query_params and request.query_params['type'] == 'location': + queryset = ( + TgItem.objects.all() + .values("location__parent") + .annotate( + inv_count=Count("location__parent"), + tmc_count=Count("tmc__tmc_id", distinct=True) + ) + .annotate( + tmc=ArrayAgg("tmc"), + ) ) - .annotate( - tmc=ArrayAgg("tmc"), + else: + queryset = ( + TgItem.objects.all() + .values("tmc__tmc_id") + .annotate( + inv_count=Count("location__parent"), + tmc_count=Count("tmc__tmc_id", distinct=True) + ) + .annotate( + location__parent=ArrayAgg("location__parent"), + tmc=ArrayAgg("tmc"), + ) ) - ) - logger.info(queryset) + # logger.info(queryset) serializer = TgStatItemSerializer(queryset, many=True) return Response(serializer.data) diff --git a/front/package-lock.json b/front/package-lock.json index 269d348..8e6134f 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -10,10 +10,12 @@ "@nuxt/image": "^1.7.0", "@nuxt/ui": "^2.16.0", "@pinia/nuxt": "^0.5.1", + "chart.js": "^3.9.1", "nuxt": "^3.11.2", "nuxt-svgo": "^4.0.1", "pinia": "^2.1.7", "vue": "^3.4.27", + "vue-chart-3": "^3.1.8", "vue-router": "^4.3.2", "vue3-telegram-login": "^1.1.0", "yup": "^1.4.0" @@ -5114,6 +5116,12 @@ "node": ">=0.8.0" } }, + "node_modules/chart.js": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.9.1.tgz", + "integrity": "sha512-Ro2JbLmvg83gXF5F4sniaQ+lTbSv18E+TIf2cOeiH1Iqd2PGFOtem+DUufMZsCJwFE7ywPOpfXFBwRTGq7dh6w==", + "license": "MIT" + }, "node_modules/chokidar": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", @@ -12545,6 +12553,22 @@ "ufo": "^1.5.3" } }, + "node_modules/vue-chart-3": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/vue-chart-3/-/vue-chart-3-3.1.8.tgz", + "integrity": "sha512-zX5ajjQi/PocEqLETlej3vp92q/tnI/Fvu2RVb++Kap8qOrXu6PXCpodi73BFrWzEGZIAnqoUxC3OIkRWD657g==", + "license": "MIT", + "dependencies": { + "@vue/runtime-core": "latest", + "@vue/runtime-dom": "latest", + "csstype": "latest", + "lodash-es": "latest" + }, + "peerDependencies": { + "chart.js": "=> ^3.1.0", + "vue": ">= 3" + } + }, "node_modules/vue-devtools-stub": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/vue-devtools-stub/-/vue-devtools-stub-0.1.0.tgz", diff --git a/front/package.json b/front/package.json index c04f0fd..5cad83a 100644 --- a/front/package.json +++ b/front/package.json @@ -19,9 +19,11 @@ "vue": "^3.4.27", "vue-router": "^4.3.2", "vue3-telegram-login": "^1.1.0", - "yup": "^1.4.0" + "yup": "^1.4.0", + "chart.js": "^3.9.1", + "vue-chart-3": "^3.1.8" }, "devDependencies": { "sass": "^1.77.2" } -} +} \ No newline at end of file diff --git a/front/pages/stat/index.vue b/front/pages/stat/index.vue index 029d097..f0fdb22 100644 --- a/front/pages/stat/index.vue +++ b/front/pages/stat/index.vue @@ -1,5 +1,8 @@ Результаты инвентаризации - + + + По организациям + По продуктам + + + {{ item.location.name }} {{ item.inv_count }} + + + {{ item.tmc[0].tmc__name }} {{ item.tmc[0].count }} + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index e8499bf..0000000 --- a/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "to_inventory", - "lockfileVersion": 3, - "requires": true, - "packages": {} -}