同步国家卫健委风险地区数据

This commit is contained in:
aixianling
2022-09-23 18:20:29 +08:00
parent 2ca0518c98
commit 4daab388ab
3 changed files with 168 additions and 93 deletions

View File

@@ -23,6 +23,7 @@
"dayjs": "^1.8.35", "dayjs": "^1.8.35",
"dvcp-ui": "^1.42.2", "dvcp-ui": "^1.42.2",
"echarts": "^5.1.2", "echarts": "^5.1.2",
"hash.js": "^1.1.7",
"mp4box": "^0.4.1", "mp4box": "^0.4.1",
"print-js": "^1.0.63", "print-js": "^1.0.63",
"serialize-javascript": "^6.0.0", "serialize-javascript": "^6.0.0",

View File

@@ -1,41 +1,45 @@
<template> <template>
<ai-list class="notice"> <ai-list class="notice">
<template slot="title"> <template slot="title">
<ai-title title="风险区域配置" isShowBottomBorder></ai-title> <ai-title title="风险区域配置" isShowBottomBorder>
<template #rightBtn>
<el-button type="primary" @click="handleSyncData">同步卫健委数据</el-button>
</template>
</ai-title>
</template> </template>
<template slot="content"> <template slot="content">
<ai-search-bar class="search-bar"> <ai-search-bar class="search-bar">
<template #left> <template #left>
<ai-select <ai-select
v-model="search.level" v-model="search.level"
clearable clearable
placeholder="请选择风险等级" placeholder="请选择风险等级"
:selectList="dict.getDict('epidemicDangerousAreaLevel')" :selectList="dict.getDict('epidemicDangerousAreaLevel')"
@change="search.current = 1, getList()"> @change="search.current = 1, getList()">
</ai-select> </ai-select>
<el-button size="small" type="primary" icon="iconfont iconAdd" @click="toAdd('')">添加</el-button> <el-button size="small" type="primary" icon="iconfont iconAdd" @click="toAdd('')">添加</el-button>
</template> </template>
<template #right> <template #right>
<el-input <el-input
v-model="search.province" v-model="search.province"
class="search-input" class="search-input"
size="small" size="small"
v-throttle="() => {search.current = 1, getList()}" v-throttle="() => {search.current = 1, getList()}"
placeholder="省级名称/市级名称/区级名称" placeholder="省级名称/市级名称/区级名称"
clearable clearable
@clear="search.current = 1, search.province = '', getList()" @clear="search.current = 1, search.province = '', getList()"
suffix-icon="iconfont iconSearch"> suffix-icon="iconfont iconSearch">
</el-input> </el-input>
</template> </template>
</ai-search-bar> </ai-search-bar>
<ai-table <ai-table
:tableData="tableData" :tableData="tableData"
:col-configs="colConfigs" :col-configs="colConfigs"
:total="total" :total="total"
style="margin-top: 6px;" style="margin-top: 6px;"
:current.sync="search.current" :current.sync="search.current"
:size.sync="search.size" :size.sync="search.size"
@getList="getList"> @getList="getList">
<el-table-column slot="options" width="140px" fixed="right" label="操作" align="center"> <el-table-column slot="options" width="140px" fixed="right" label="操作" align="center">
<template slot-scope="{ row }"> <template slot-scope="{ row }">
<div class="table-options"> <div class="table-options">
@@ -50,92 +54,102 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import {mapState} from 'vuex'
export default { import {getRiskArea} from "../riskareaCrawler";
name: 'List',
props: { export default {
instance: Function, name: 'List',
dict: Object,
moduleName: String
},
data() { props: {
return { instance: Function,
search: { dict: Object,
current: 1, moduleName: String
size: 10, },
level: '',
province: ''
},
currIndex: -1,
areaList: [],
total: 10,
colConfigs: [
{ prop: 'province', label: '省级', align: 'left', width: '200px' },
{ prop: 'city', label: '市级', align: 'center' },
{ prop: 'district', label: '区级', align: 'center' },
{ prop: 'town', label: '镇级', align: 'center' },
{ prop: 'village', label: '村级', align: 'center' },
{ prop: 'level', label: '等级', align: 'center', formart: v => this.dict.getLabel('epidemicDangerousAreaLevel', v) },
{ prop: 'createTime', label: '设置时间', align: 'center' },
{ prop: 'createUserName', label: '添加人', align: 'center' },
{ slot: 'options', label: '操作', align: 'center' }
],
areaName: '',
unitName: '',
tableData: []
}
},
computed: { data() {
...mapState(['user']) return {
}, search: {
current: 1,
size: 10,
level: '',
province: ''
},
currIndex: -1,
areaList: [],
total: 10,
colConfigs: [
{prop: 'province', label: '省级', align: 'left', width: '200px'},
{prop: 'city', label: '市级', align: 'center'},
{prop: 'district', label: '区级', align: 'center'},
{prop: 'town', label: '镇级', align: 'center'},
{prop: 'village', label: '村级', align: 'center'},
{prop: 'level', label: '等级', align: 'center', formart: v => this.dict.getLabel('epidemicDangerousAreaLevel', v)},
{prop: 'createTime', label: '设置时间', align: 'center'},
{prop: 'createUserName', label: '添加人', align: 'center'},
{slot: 'options', label: '操作', align: 'center'}
],
areaName: '',
unitName: '',
tableData: []
}
},
created() { computed: {
this.dict.load('epidemicDangerousAreaLevel').then(() => { ...mapState(['user'])
this.getList() },
created() {
this.dict.load('epidemicDangerousAreaLevel').then(() => {
this.getList()
})
},
methods: {
getList() {
this.instance.post(`/app/appepidemicpreventionriskarea/list`, null, {
params: {
...this.search
}
}).then(res => {
if (res.code == 0) {
this.tableData = res.data.records
this.total = res.data.total
}
}) })
}, },
methods: { remove(id) {
getList() { this.$confirm('确定删除该数据?').then(() => {
this.instance.post(`/app/appepidemicdangerousarea/list`, null, { this.instance.post(`/app/appepidemicpreventionriskarea/delete?ids=${id}`).then(res => {
params: {
...this.search
}
}).then(res => {
if (res.code == 0) { if (res.code == 0) {
this.tableData = res.data.records this.$message.success('删除成功!')
this.total = res.data.total this.getList()
} }
}) })
}, })
},
remove(id) { toAdd(id) {
this.$confirm('确定删除该数据?').then(() => { this.$emit('change', {
this.instance.post(`/app/appepidemicdangerousarea/delete?ids=${id}`).then(res => { type: 'Add',
if (res.code == 0) { params: {
this.$message.success('删除成功!') id: id || ''
this.getList() }
} })
}) },
}) handleSyncData() {
}, getRiskArea(this.instance).then(res => {
if (res?.code == 0) {
toAdd(id) { this.getList()
this.$emit('change', { this.$message.success("同步完毕!")
type: 'Add', }
params: { })
id: id || ''
}
})
}
} }
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.notice { .notice {
} }
</style> </style>

View File

@@ -0,0 +1,60 @@
import hash from "hash.js"
const nonceHeader = "123456789abcdefg"
let http = {}, riskareaList = []
const getSHA256 = key => hash.sha256().update(key).digest("hex")
const getData = (timestampHeader) => {
return http.post("/app/appepidemicpreventionriskarea/apiForwardPost", {
appId: "NcApplication",
key: "3C502C97ABDA40D0A60FBEE50FAAD1DA",
nonceHeader,
paasHeader: "zdww",
signatureHeader: getSHA256(`${timestampHeader}23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA${nonceHeader}${timestampHeader}`).toUpperCase(),
timestampHeader
}, {
withoutToken: true,
headers: {
Referer: "http://bmfw.www.gov.cn/yqfxdjcx/risk.html",
"x-wif-nonce": "QkjjtiLM2dCratiA",
"x-wif-paasid": "smt-application",
"x-wif-signature": getSHA256(`${timestampHeader}fTN2pfuisxTavbTuYVSsNJHetwq5bJvCQkjjtiLM2dCratiA${timestampHeader}`).toUpperCase(),
"x-wif-timestamp": timestampHeader
},
params: {
url: "http://bmfw.www.gov.cn/bjww/interface/interfaceJson"
}
}).then(res => {
if (res?.data?.data) {
const {highlist, lowlist, middlelist} = res.data.data
return Promise.all([
handleData(highlist, 2),
handleData(middlelist, 1),
// handleData(lowlist, 0)
])
}
})
}
const transName2Code = area_name => http.post("/app/appepidemicpreventionriskarea/transformationAreaName", null, {
params: {area_name}
}).then(res => {
if (res?.data) {
return res.data
}
})
const handleData = (list, riskLevel) => {
return Promise.all(list.map(e => {
const {province, city, county: district, area_name} = e
return transName2Code(area_name).then(areaId => e?.communitys?.map(address => riskareaList.push({
province, city, district, address, areaId,
level: riskLevel,
createUserName: "国家卫健委"
})
))
}))
}
export const getRiskArea = ins => {
http = ins
const timestamp = Math.round(new Date().getTime() / 1000).toString()
riskareaList = []
return getData(timestamp).then(() => http.post("/app/appepidemicpreventionriskarea/batchInsert", riskareaList))
}