Browse Source

更正错别字

dev
CODE 1 year ago
parent
commit
371bfb5a40
  1. 4
      api/app/lib/controllers/report/index.js
  2. 4
      api/app/lib/models/village_distance.js
  3. 2
      scripts/1.4.0/data/1_calc_village_distance/Dockerfilenew
  4. 38
      scripts/1.4.0/data/1_calc_village_distance/index.js
  5. 4
      scripts/1.4.0/schema/2.create_village_table.sql

4
api/app/lib/controllers/report/index.js

@ -698,9 +698,9 @@ async function roadSpotPrepare (ctx) {
}
const villageNearRes = await sequelize.query(`
SELECT id,calc_village,diatance FROM village_distance
SELECT id,calc_village,distance FROM village_distance
WHERE origin_village = ${spotFirstVillageId}
ORDER BY diatance ASC
ORDER BY distance ASC
`, { type: QueryTypes.SELECT })
let villageCheckIdList = villageNearRes.map(item => item.calc_village)

4
api/app/lib/models/village_distance.js

@ -41,13 +41,13 @@ module.exports = dc => {
model: "village"
}
},
diatance: {
distance: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
comment: "距离 m",
primaryKey: false,
field: "diatance",
field: "distance",
autoIncrement: false
}
}, {

2
scripts/1.4.0/data/1_calc_village_distance/Dockerfilenew

@ -1,5 +1,5 @@
FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2
COPY ./scripts/1.3.1/data/1_insert_report_data /var/app
COPY ./scripts/1.4.0/data/1_calc_village_distance /var/app
WORKDIR /var/app
RUN npm cache clean -f
RUN rm -rf package-lock.json

38
scripts/1.4.0/data/1_calc_village_distance/index.js

@ -11,6 +11,7 @@ try {
password: '123',
database: 'highways4good',
})
const godKey = '21c2d970e1646bb9a795900dd00093ce'
function getDistance (lat1, lon1, lat2, lon2) {
var R = 6371000; // 半径 of the earth in meters
@ -44,12 +45,24 @@ try {
await client.query('BEGIN')
console.log(`开始`);
// 遍历南昌县所有村
const nanchangRes = await request.get(`https://restapi.amap.com/v3/config/district?key=${godKey}&keywords=360100&subdistrict=1`)
console.log(nanchangRes.body);
let townshipList = nanchangRes.body.districts[0].districts
console.log(townshipList);
for (let t of townshipList) {
console.log(`${t.name}`);
let pageNum = 1
let continueSearch = true
for (; continueSearch;) {
console.log(`查询第${pageNum}`);
const res = await request.get(`https://restapi.amap.com/v5/place/text?key=21c2d970e1646bb9a795900dd00093ce&keywords=%E6%9D%91%E5%A7%94%E4%BC%9A%7C%E6%9D%91%E6%B0%91%E5%A7%94%E5%91%98%E4%BC%9A&types=130106&region=360121&citylimit=true&page_size=25&page_num=${pageNum}&extensions=all`)
// const res = await request.get(`https://restapi.amap.com/v5/place/text?key=${godKey}&types=130106&region=360000&citylimit=true&page_size=25&page_num=${pageNum}&extensions=all`)
const res = await request.get(`https://restapi.amap.com/v3/place/text?key=${godKey}&keywords=%E6%9D%91%E5%A7%94%E4%BC%9A%7C%E6%9D%91%E6%B0%91%E5%A7%94%E5%91%98%E4%BC%9A&page_size=25&types=130106&citylimit=true&city=${t.adcode}&page=${pageNum}`)
await new Promise(resolve => setTimeout(() => resolve(), 2000));
// console.log(res.body);
const data = res.body
@ -61,6 +74,7 @@ try {
pageNum++
}
for await (let p of data.pois) {
console.log(p.name);
if (p.name.includes('村委会') || p.name.includes('村民委员会')) {
let vName = p.name.replace('村委会', '').replace('村民委员会', '').replace(/\(.*?\)/g, '')
@ -81,19 +95,26 @@ try {
vName = vName + '村'
}
console.log(`${vName}`);
// console.log(`${vName}`);
let locationArr = p.location.split(',')
// 查询镇名是否存在
const existRes = await client.query(
let existRes = await client.query(
`SELECT * FROM village WHERE name=$1`,
[vName]
)
if (existRes.rowCount == 0) {
existRes = await client.query(
`SELECT * FROM village WHERE name=$1`,
[vName + '委会']
)
}
if (existRes.rowCount == 0) {
} else {
let existV = existRes[0]
let existV = existRes.rows[0]
// console.log(existRes);
await client.query(
`UPDATE village SET longitude=$1, latitude=$2 WHERE id=$3`,
[locationArr[0], locationArr[1], existV.id]
@ -102,6 +123,7 @@ try {
}
}
}
}
const allVillagesRes = await client.query(
`SELECT * FROM village`
@ -121,7 +143,8 @@ try {
continue
}
let distance = getDistance(v.latitude, v.longitude, vv.latitude, vv.longitude)
console.log(`${v.name}${vv.name} 的距离为 ${distance}`);
// console.log(`${v.name} 与 ${vv.name} 的距离为 ${distance} 米`);
distance = Math.round(distance)
const existRes = await client.query(
@ -134,8 +157,9 @@ try {
[v.id, vv.id, distance]
)
} else {
let upSql = `UPDATE village_distance SET distance=$1 WHERE origin_village=$2 AND calc_village=$3`
await client.query(
`UPDATE village_distance SET distance=$1 WHERE origin_village=$2 AND calc_village=$`
upSql
, [distance, v.id, vv.id]
)
}

4
scripts/1.4.0/schema/2.create_village_table.sql

@ -34,7 +34,7 @@ create table if not exists village_distance
calc_village integer
constraint village_distance_village_id_fk_2
references village,
diatance integer
distance integer
);
comment on table village_distance is '村之间的距离';
@ -43,7 +43,7 @@ comment on column village_distance.origin_village is '原点村庄';
comment on column village_distance.calc_village is '相对计算村庄';
comment on column village_distance.diatance is '距离 m';
comment on column village_distance.distance is '距离 m';
create unique index if not exists village_distance_id_uindex
on village_distance (id);

Loading…
Cancel
Save