重组目录结构
This commit is contained in:
parent
e8e09eccb2
commit
4f5d2c25bb
|
|
@ -16,12 +16,13 @@
|
||||||
"@types/lodash": "^4.14.168",
|
"@types/lodash": "^4.14.168",
|
||||||
"@types/luxon": "^2.0.9",
|
"@types/luxon": "^2.0.9",
|
||||||
"@types/mocha": "^8.2.0",
|
"@types/mocha": "^8.2.0",
|
||||||
"@types/node": "^14.14.25",
|
"@types/node": "^14.18.12",
|
||||||
"@types/react": "^17.0.2",
|
"@types/react": "^17.0.2",
|
||||||
"@types/uuid": "^8.3.0",
|
"@types/uuid": "^8.3.0",
|
||||||
"assert": "^2.0.0",
|
"assert": "^2.0.0",
|
||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
|
"isomorphic-fetch": "^3.0.0",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
"oak-domain": "file:../oak-domain",
|
"oak-domain": "file:../oak-domain",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
|
|
@ -30,7 +31,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "npm link oak-domain oak-memory-tree-store oak-trigger-executor oak-debug-store",
|
"postinstall": "npm link oak-domain oak-memory-tree-store oak-trigger-executor oak-debug-store",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "ts-node ./src/features/token.ts"
|
"test": "ts-node ./scripts/getAmapArea.ts"
|
||||||
},
|
},
|
||||||
"main": "src/index"
|
"main": "src/index"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,167 @@
|
||||||
|
/**
|
||||||
|
* 用于更新高德数据库中的adCode信息到本地src/data/area.json中
|
||||||
|
*/
|
||||||
|
import 'isomorphic-fetch';
|
||||||
|
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';
|
||||||
|
|
||||||
|
|
||||||
|
const KEY = '4f3d4499850ba51429b9dece8cedd8d2';
|
||||||
|
|
||||||
|
async function acquireAmap(keyWords: string, subdistrict: number) {
|
||||||
|
const url = `https://restapi.amap.com/v3/config/district?keywords=${encodeURIComponent(keyWords)}&subdistrict=${subdistrict}&key=${KEY}`;
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function processRepeatedAdCode(districts: any[], parentAdCode: string) {
|
||||||
|
// 高德的street的adCode和父亲相同,这里统一处理一下
|
||||||
|
let jdCount = 0;
|
||||||
|
let zCount = 100;
|
||||||
|
let oCount = 400;
|
||||||
|
let xCount = 200;
|
||||||
|
const districts2 = districts.map(
|
||||||
|
(ele) => {
|
||||||
|
const { name, adcode } = ele;
|
||||||
|
let ele2 = ele;
|
||||||
|
if (adcode === parentAdCode) {
|
||||||
|
if (name.endsWith('街道')) {
|
||||||
|
ele2 = Object.assign(ele, { adcode: parseInt(adcode) * 1000 + jdCount });
|
||||||
|
jdCount++;
|
||||||
|
}
|
||||||
|
else if (name.endsWith('镇')) {
|
||||||
|
ele2 = Object.assign(ele, { adcode: parseInt(adcode) * 1000 + zCount });
|
||||||
|
zCount++;
|
||||||
|
}
|
||||||
|
else if (name.endsWith('乡')) {
|
||||||
|
ele2 = Object.assign(ele, { adcode: parseInt(adcode) * 1000 + xCount });
|
||||||
|
xCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ele2 = Object.assign(ele, { adcode: parseInt(adcode) * 1000 + oCount });
|
||||||
|
oCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ele2;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return districts2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 省份直接取到街道,然后存储
|
||||||
|
* @param provinceName
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
/* function getProvince(provinceName) {
|
||||||
|
return acquireAmap(provinceName, 3)
|
||||||
|
.then(
|
||||||
|
(result) => {
|
||||||
|
const { districts: cities, adcode: provinceCode } = result.districts[0];
|
||||||
|
cities.forEach(
|
||||||
|
(city) => {
|
||||||
|
const { districts, adcode: cityCode } = city;
|
||||||
|
const districts2 = processRepeatedAdCode(districts, cityCode);
|
||||||
|
saveDistricts(districts2, cityCode);
|
||||||
|
districts2.forEach(
|
||||||
|
(district) => {
|
||||||
|
const { districts: streets, adcode: districtCode } = district;
|
||||||
|
const streets2 = processRepeatedAdCode(streets, districtCode);
|
||||||
|
saveDistricts(streets2, districtCode);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} */
|
||||||
|
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const area: FormCreateData<Area>[] = [];
|
||||||
|
function saveAreas(areas: any[], parentId: string | null) {
|
||||||
|
areas.forEach(
|
||||||
|
(ele) => {
|
||||||
|
const { adcode, center, citycode, level, name } = ele;
|
||||||
|
const coords = center.split(',');
|
||||||
|
area.push({
|
||||||
|
code: adcode,
|
||||||
|
level,
|
||||||
|
parentId,
|
||||||
|
name,
|
||||||
|
id: adcode,
|
||||||
|
center: {
|
||||||
|
type: 'point',
|
||||||
|
coordinate: [parseFloat(coords[0]), parseFloat(coords[1])],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await acquireAmap('中国', 1);
|
||||||
|
const { districts } = result;
|
||||||
|
const country = districts[0];
|
||||||
|
saveAreas([country], null);
|
||||||
|
const { districts: provinces, adcode: countryCode } = country;
|
||||||
|
saveAreas(provinces, countryCode);
|
||||||
|
|
||||||
|
for (const dist of districts) {
|
||||||
|
const result2 = await acquireAmap(dist.name, 3);
|
||||||
|
const { districts: cities, adcode: provinceCode } = result2.districts[0];
|
||||||
|
saveAreas(cities, provinceCode);
|
||||||
|
for (const city of cities) {
|
||||||
|
const { districts, adcode: cityCode } = city;
|
||||||
|
const districts2 = processRepeatedAdCode(districts, cityCode);
|
||||||
|
saveAreas(districts2, cityCode);
|
||||||
|
districts2.forEach(
|
||||||
|
(district) => {
|
||||||
|
const { districts: streets, adcode: districtCode } = district;
|
||||||
|
const streets2 = processRepeatedAdCode(streets, districtCode);
|
||||||
|
saveAreas(streets2, districtCode);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(`${__dirname}/../src/data/area.json`, JSON.stringify(area));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main().then(
|
||||||
|
() => console.log('success')
|
||||||
|
);
|
||||||
|
/*
|
||||||
|
acquireAmap('中国', 1)
|
||||||
|
.then(
|
||||||
|
(result) => {
|
||||||
|
saveDistricts(result.districts, null);
|
||||||
|
const country = result.districts[0];
|
||||||
|
const { districts: provinces, adcode: countryCode } = country;
|
||||||
|
saveDistricts(provinces, countryCode);
|
||||||
|
function provIter(idx) {
|
||||||
|
if (idx === provinces.length) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
const prov = provinces[idx];
|
||||||
|
return getProvince(prov.name)
|
||||||
|
.then(
|
||||||
|
() => {
|
||||||
|
console.log(`${prov.name}处理完毕`);
|
||||||
|
return provIter(idx + 1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return provIter(0);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(
|
||||||
|
(err) => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
); */
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const ROOT_ROLE_ID = 'oak-root-role';
|
||||||
|
export const ROOT_USER_ID = 'oak-root-user';
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,5 @@
|
||||||
|
import area from './area.json';
|
||||||
|
|
||||||
|
export {
|
||||||
|
area,
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { userRoles, users, roles } from './userRole';
|
||||||
|
import { area } from './area';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
userRole: userRoles,
|
||||||
|
user: users,
|
||||||
|
role: roles,
|
||||||
|
area,
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { FormCreateData } from 'oak-domain/lib/types/Entity';
|
||||||
|
import { OpSchema as User } from 'oak-domain/lib/base-domain/User/Schema';
|
||||||
|
import { OpSchema as Role } from 'oak-domain/lib/base-domain/Role/Schema';
|
||||||
|
import { OpSchema as UserRole } from 'oak-domain/lib/base-domain/UserRole/Schema';
|
||||||
|
import { ROOT_ROLE_ID, ROOT_USER_ID } from '../constants';
|
||||||
|
export const users: Array<FormCreateData<User>> = [
|
||||||
|
{
|
||||||
|
password: 'oak@2022',
|
||||||
|
name: 'root',
|
||||||
|
id: ROOT_USER_ID,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
export const roles: Array<FormCreateData<Role>> = [
|
||||||
|
{
|
||||||
|
name: 'root',
|
||||||
|
id: ROOT_ROLE_ID,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
export const userRoles: Array<FormCreateData<UserRole>> = [
|
||||||
|
{
|
||||||
|
userId: ROOT_USER_ID,
|
||||||
|
roleId: ROOT_ROLE_ID,
|
||||||
|
relation: 'owner',
|
||||||
|
id: 'root_user_role',
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import aspectDict from "./aspects";
|
import aspectDict from "./aspects";
|
||||||
|
import triggers from "./triggers";
|
||||||
|
import data from "./data";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
triggers,
|
||||||
|
data,
|
||||||
aspectDict,
|
aspectDict,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
export default [];
|
||||||
|
|
@ -61,7 +61,8 @@
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
/* Advanced Options */
|
/* Advanced Options */
|
||||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*" ],
|
"src/**/*" ],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue