|
@@ -3,13 +3,11 @@ import { z } from '@hono/zod-openapi';
|
|
|
import { AreaServiceMt } from '../../modules/areas/area.service.mt';
|
|
import { AreaServiceMt } from '../../modules/areas/area.service.mt';
|
|
|
import { AreaLevel } from '../../modules/areas/area.entity.mt';
|
|
import { AreaLevel } from '../../modules/areas/area.entity.mt';
|
|
|
import { AppDataSource } from '@d8d/shared-utils';
|
|
import { AppDataSource } from '@d8d/shared-utils';
|
|
|
|
|
+import { authMiddleware } from '@d8d/auth-module-mt';
|
|
|
|
|
+import { AuthContext } from '@d8d/shared-types';
|
|
|
|
|
|
|
|
// 省份查询参数Schema(多租户)
|
|
// 省份查询参数Schema(多租户)
|
|
|
const getProvincesSchema = z.object({
|
|
const getProvincesSchema = z.object({
|
|
|
- tenantId: z.coerce.number<number>().int().positive('租户ID必须为正整数').openapi({
|
|
|
|
|
- example: 1,
|
|
|
|
|
- description: '租户ID'
|
|
|
|
|
- }),
|
|
|
|
|
page: z.coerce.number<number>().int().min(1).default(1).openapi({
|
|
page: z.coerce.number<number>().int().min(1).default(1).openapi({
|
|
|
example: 1,
|
|
example: 1,
|
|
|
description: '页码'
|
|
description: '页码'
|
|
@@ -22,10 +20,6 @@ const getProvincesSchema = z.object({
|
|
|
|
|
|
|
|
// 城市查询参数Schema(多租户)
|
|
// 城市查询参数Schema(多租户)
|
|
|
const getCitiesSchema = z.object({
|
|
const getCitiesSchema = z.object({
|
|
|
- tenantId: z.coerce.number<number>().int().positive('租户ID必须为正整数').openapi({
|
|
|
|
|
- example: 1,
|
|
|
|
|
- description: '租户ID'
|
|
|
|
|
- }),
|
|
|
|
|
provinceId: z.coerce.number<number>().int().positive('省份ID必须为正整数').openapi({
|
|
provinceId: z.coerce.number<number>().int().positive('省份ID必须为正整数').openapi({
|
|
|
example: 1,
|
|
example: 1,
|
|
|
description: '省份ID'
|
|
description: '省份ID'
|
|
@@ -42,10 +36,6 @@ const getCitiesSchema = z.object({
|
|
|
|
|
|
|
|
// 区县查询参数Schema(多租户)
|
|
// 区县查询参数Schema(多租户)
|
|
|
const getDistrictsSchema = z.object({
|
|
const getDistrictsSchema = z.object({
|
|
|
- tenantId: z.coerce.number<number>().int().positive('租户ID必须为正整数').openapi({
|
|
|
|
|
- example: 1,
|
|
|
|
|
- description: '租户ID'
|
|
|
|
|
- }),
|
|
|
|
|
cityId: z.coerce.number<number>().int().positive('城市ID必须为正整数').openapi({
|
|
cityId: z.coerce.number<number>().int().positive('城市ID必须为正整数').openapi({
|
|
|
example: 34,
|
|
example: 34,
|
|
|
description: '城市ID'
|
|
description: '城市ID'
|
|
@@ -62,10 +52,6 @@ const getDistrictsSchema = z.object({
|
|
|
|
|
|
|
|
// 街道查询参数Schema(多租户)
|
|
// 街道查询参数Schema(多租户)
|
|
|
const getTownsSchema = z.object({
|
|
const getTownsSchema = z.object({
|
|
|
- tenantId: z.coerce.number<number>().int().positive('租户ID必须为正整数').openapi({
|
|
|
|
|
- example: 1,
|
|
|
|
|
- description: '租户ID'
|
|
|
|
|
- }),
|
|
|
|
|
districtId: z.coerce.number<number>().int().positive('区县ID必须为正整数').openapi({
|
|
districtId: z.coerce.number<number>().int().positive('区县ID必须为正整数').openapi({
|
|
|
example: 3401,
|
|
example: 3401,
|
|
|
description: '区县ID'
|
|
description: '区县ID'
|
|
@@ -234,6 +220,7 @@ const getDistrictsRoute = createRoute({
|
|
|
const getTownsRoute = createRoute({
|
|
const getTownsRoute = createRoute({
|
|
|
method: 'get',
|
|
method: 'get',
|
|
|
path: '/towns',
|
|
path: '/towns',
|
|
|
|
|
+ middleware: [ authMiddleware ],
|
|
|
request: {
|
|
request: {
|
|
|
query: getTownsSchema
|
|
query: getTownsSchema
|
|
|
},
|
|
},
|
|
@@ -255,10 +242,11 @@ const getTownsRoute = createRoute({
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-const app = new OpenAPIHono()
|
|
|
|
|
|
|
+const app = new OpenAPIHono<AuthContext>()
|
|
|
.openapi(getProvincesRoute, async (c) => {
|
|
.openapi(getProvincesRoute, async (c) => {
|
|
|
try {
|
|
try {
|
|
|
- const { tenantId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
|
|
+ const { page, pageSize } = c.req.valid('query');
|
|
|
|
|
+ const tenantId = c.get('tenantId')!;
|
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
|
|
|
|
|
|
// 使用高效查询方法获取指定租户的省份数据
|
|
// 使用高效查询方法获取指定租户的省份数据
|
|
@@ -292,7 +280,8 @@ const app = new OpenAPIHono()
|
|
|
})
|
|
})
|
|
|
.openapi(getCitiesRoute, async (c) => {
|
|
.openapi(getCitiesRoute, async (c) => {
|
|
|
try {
|
|
try {
|
|
|
- const { tenantId, provinceId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
|
|
+ const { provinceId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
+ const tenantId = c.get('tenantId')!;
|
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
|
|
|
|
|
|
// 使用高效查询方法获取指定租户和省份下的城市数据
|
|
// 使用高效查询方法获取指定租户和省份下的城市数据
|
|
@@ -326,11 +315,12 @@ const app = new OpenAPIHono()
|
|
|
})
|
|
})
|
|
|
.openapi(getDistrictsRoute, async (c) => {
|
|
.openapi(getDistrictsRoute, async (c) => {
|
|
|
try {
|
|
try {
|
|
|
- const { tenantId, cityId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
|
|
+ const { cityId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
+ const tenantId = c.get('tenantId')!;
|
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
|
|
|
|
|
|
// 使用高效查询方法获取指定租户和城市下的区县数据
|
|
// 使用高效查询方法获取指定租户和城市下的区县数据
|
|
|
- const districts = await areaService.getAreasByLevelAndParent(tenantId, AreaLevel.DISTRICT, cityId);
|
|
|
|
|
|
|
+ const districts = await areaService.getAreasByLevelAndParent(tenantId, AreaLevel.DISTRICT, cityId!);
|
|
|
|
|
|
|
|
// 分页
|
|
// 分页
|
|
|
const startIndex = (page - 1) * pageSize;
|
|
const startIndex = (page - 1) * pageSize;
|
|
@@ -360,11 +350,12 @@ const app = new OpenAPIHono()
|
|
|
})
|
|
})
|
|
|
.openapi(getTownsRoute, async (c) => {
|
|
.openapi(getTownsRoute, async (c) => {
|
|
|
try {
|
|
try {
|
|
|
- const { tenantId, districtId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
|
|
+ const { districtId, page, pageSize } = c.req.valid('query');
|
|
|
|
|
+ const tenantId = c.get('tenantId')!;
|
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
const areaService = new AreaServiceMt(AppDataSource);
|
|
|
|
|
|
|
|
// 使用高效查询方法获取指定租户和区县下的街道数据
|
|
// 使用高效查询方法获取指定租户和区县下的街道数据
|
|
|
- const towns = await areaService.getAreasByLevelAndParent(tenantId, AreaLevel.TOWN, districtId);
|
|
|
|
|
|
|
+ const towns = await areaService.getAreasByLevelAndParent(tenantId, AreaLevel.TOWN, districtId!);
|
|
|
|
|
|
|
|
// 分页
|
|
// 分页
|
|
|
const startIndex = (page - 1) * pageSize;
|
|
const startIndex = (page - 1) * pageSize;
|