area.json

This commit is contained in:
Xu Chang 2022-04-09 17:24:03 +08:00
parent 8c15d3afa5
commit 99b6e45a8e
15 changed files with 58 additions and 47 deletions

View File

@ -12,6 +12,7 @@ export declare type OpSchema = {
$$removeAt$$?: Datetime | null;
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parentId?: ForeignKey<"area"> | null;
code: String<12>;
center: Geo;
@ -24,6 +25,7 @@ export declare type Schema = {
$$removeAt$$?: Datetime | null;
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parentId?: ForeignKey<"area"> | null;
code: String<12>;
center: Geo;
@ -39,6 +41,7 @@ declare type AttrFilter = {
$$updateAt$$: Q_DateValue;
name: Q_StringValue;
level: Q_EnumValue<'province' | 'city' | 'district' | 'street' | 'country'>;
depth: Q_EnumValue<0 | 1 | 2 | 3 | 4>;
parentId: Q_StringValue | SubQuery.AreaIdSubQuery;
parent: Filter;
code: Q_StringValue;
@ -52,6 +55,7 @@ export declare type Projection = {
$$updateAt$$?: 1;
name?: 1;
level?: 1;
depth?: 1;
parentId?: 1;
parent?: Projection;
code?: 1;
@ -67,6 +71,7 @@ export declare type ExportProjection = {
$$updateAt$$?: string;
name?: string;
level?: string;
depth?: string;
parentId?: string;
parent?: ExportProjection;
code?: string;
@ -84,6 +89,7 @@ export declare type SortAttr = OneOf<{
$$updateAt$$: 1;
name: 1;
level: 1;
depth: 1;
parentId: 1;
parent: SortAttr;
code: 1;

View File

@ -15,6 +15,13 @@ exports.desc = {
length: 16
}
},
depth: {
type: "int",
params: {
precision: 8,
scale: 2
}
},
parentId: {
type: "ref",
ref: "area"

1
lib/data/area-debug.json Normal file

File diff suppressed because one or more lines are too long

2
lib/data/area.d.ts vendored
View File

@ -1,2 +1,2 @@
import area from './area.json';
declare const area: any[];
export { area, };

View File

@ -5,4 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.area = void 0;
const area_json_1 = __importDefault(require("./area.json"));
exports.area = area_json_1.default;
const area_debug_json_1 = __importDefault(require("./area-debug.json"));
const area = process.env.NODE_ENV === 'production' ? area_json_1.default : area_debug_json_1.default;
exports.area = area;

File diff suppressed because one or more lines are too long

32
lib/data/index.d.ts vendored
View File

@ -2,36 +2,6 @@ declare const _default: {
userRole: import("../base-ed/UserRole/Schema").CreateOperationData[];
user: import("../base-ed/User/Schema").CreateOperationData[];
role: import("../base-ed/Role/Schema").CreateOperationData[];
area: ({
code: string;
level: string;
parentId: null;
name: string;
id: string;
center: {
type: string;
coordinate: number[];
};
} | {
code: string;
level: string;
parentId: string;
name: string;
id: string;
center: {
type: string;
coordinate: number[];
};
} | {
code: number;
level: string;
parentId: string;
name: string;
id: number;
center: {
type: string;
coordinate: number[];
};
})[];
area: any[];
};
export default _default;

View File

@ -3,6 +3,7 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
export interface Schema extends EntityShape {
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parent?: Schema;
code: String<12>;
center: Geo;

View File

@ -2,9 +2,10 @@
* adCode信息到本地src/data/area.json中
*/
import 'isomorphic-fetch';
import assert from 'assert';
import { writeFileSync } from 'fs-extra';
import { FormCreateData } from 'oak-domain/lib/types/Entity';
import { OpSchema as Area } from 'oak-domain/lib/base-domain/Area/Schema';
import { OpSchema as Area } from '../src/base-ed/Area/Schema';
const KEY = '4f3d4499850ba51429b9dece8cedd8d2';
@ -81,17 +82,19 @@ function processRepeatedAdCode(districts: any[], parentAdCode: string) {
async function main() {
const area: FormCreateData<Area>[] = [];
function saveAreas(areas: any[], parentId: string | null) {
const areasss: FormCreateData<Area>[] = [];
const streetsss: FormCreateData<Area>[] = [];
function saveAreas(areas: any[], parentId: string | null, depth: 0 | 1 | 2 | 3 | 4, dest: FormCreateData<Area>[] = areasss) {
areas.forEach(
(ele) => {
const { adcode, center, citycode, level, name } = ele;
const coords = center.split(',');
area.push({
dest.push({
code: adcode,
level,
parentId,
name,
depth,
id: adcode,
center: {
type: 'point',
@ -105,29 +108,33 @@ async function main() {
const result = await acquireAmap('中国', 1);
const { districts } = result;
const country = districts[0];
saveAreas([country], null);
saveAreas([country], null, 0);
const { districts: provinces, adcode: countryCode } = country;
saveAreas(provinces, countryCode);
saveAreas(provinces, countryCode, 1);
for (const dist of districts) {
for (const dist of provinces) {
const result2 = await acquireAmap(dist.name, 3);
const { districts: cities, adcode: provinceCode } = result2.districts[0];
saveAreas(cities, provinceCode);
// cities.forEach((ele: any) => assert(ele.level === 'city'));
saveAreas(cities, provinceCode, 2);
for (const city of cities) {
const { districts, adcode: cityCode } = city;
const districts2 = processRepeatedAdCode(districts, cityCode);
saveAreas(districts2, cityCode);
// districts2.forEach((ele: any) => assert(ele.level === 'district'));
saveAreas(districts2, cityCode, 3);
districts2.forEach(
(district) => {
const { districts: streets, adcode: districtCode } = district;
const streets2 = processRepeatedAdCode(streets, districtCode);
saveAreas(streets2, districtCode);
// streets2.forEach((ele: any) => assert(ele.level === 'street'));
saveAreas(streets2, districtCode, 4, streetsss);
}
);
}
}
writeFileSync(`${__dirname}/../src/data/area.json`, JSON.stringify(area));
writeFileSync(`${__dirname}/../src/data/area-debug.json`, JSON.stringify(areasss));
writeFileSync(`${__dirname}/../src/data/area.json`, JSON.stringify(areasss.concat(streetsss)));
}

View File

@ -12,6 +12,7 @@ export type OpSchema = {
$$removeAt$$?: Datetime | null;
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parentId?: ForeignKey<"area"> | null;
code: String<12>;
center: Geo;
@ -24,6 +25,7 @@ export type Schema = {
$$removeAt$$?: Datetime | null;
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parentId?: ForeignKey<"area"> | null;
code: String<12>;
center: Geo;
@ -39,6 +41,7 @@ type AttrFilter = {
$$updateAt$$: Q_DateValue;
name: Q_StringValue;
level: Q_EnumValue<'province' | 'city' | 'district' | 'street' | 'country'>;
depth: Q_EnumValue<0 | 1 | 2 | 3 | 4>;
parentId: Q_StringValue | SubQuery.AreaIdSubQuery;
parent: Filter;
code: Q_StringValue;
@ -52,6 +55,7 @@ export type Projection = {
$$updateAt$$?: 1;
name?: 1;
level?: 1;
depth?: 1;
parentId?: 1;
parent?: Projection;
code?: 1;
@ -67,6 +71,7 @@ export type ExportProjection = {
$$updateAt$$?: string;
name?: string;
level?: string;
depth?: string;
parentId?: string;
parent?: ExportProjection;
code?: string;
@ -84,6 +89,7 @@ export type SortAttr = OneOf<{
$$updateAt$$: 1;
name: 1;
level: 1;
depth: 1;
parentId: 1;
parent: SortAttr;
code: 1;

View File

@ -14,6 +14,13 @@ export const desc: StorageDesc<OpSchema> = {
length: 16
}
},
depth: {
type: "int",
params: {
precision: 8,
scale: 2
}
},
parentId: {
type: "ref",
ref: "area"

1
src/data/area-debug.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,7 @@
import area from './area.json';
import area2 from './area.json';
import area_debug from './area-debug.json';
const area = process.env.NODE_ENV === 'production' ? area2 : area_debug;
export {
area,
};

View File

@ -4,6 +4,7 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
export interface Schema extends EntityShape {
name: String<32>;
level: 'province' | 'city' | 'district' | 'street' | 'country';
depth: 0 | 1 | 2 | 3 | 4;
parent?: Schema;
code: String<12>;
center: Geo;