xyc
11 小时以前 5b41c8896ef7850be2672e45b69bb58e149729ec
traffic-audit-web/src/views/DataImport.vue
@@ -10,6 +10,7 @@
          <el-menu-item index="/explain">企业解释</el-menu-item>
          <el-menu-item index="/audit">审核结果</el-menu-item>
          <el-menu-item index="/report">报表生成</el-menu-item>
          <el-menu-item index="/ledger-audit">事后核查</el-menu-item>
          <el-submenu index="/special-stats">
            <template slot="title">专项统计</template>
            <el-menu-item index="/holiday-stat">节假日</el-menu-item>
@@ -51,6 +52,20 @@
                             @click="downloadTemplate">下载模板</el-link>
                    <span v-if="importType === 'cityTaxiAuth'" class="slow-tip">该类型约 4 万+ 行,预计耗时 1 分钟以内</span>
                  </div>
                  <template v-if="moduleSel[g.key] === 'trackMileage'">
                    <span class="source-label">数据来源</span>
                    <el-select v-model="trackMileageSource" size="small" style="width:150px" @change="onTrackSourceChange">
                      <el-option label="省重载平台" value="PROVINCIAL"></el-option>
                      <el-option label="市州第三方" value="CITY_THIRD_PARTY"></el-option>
                    </el-select>
                    <template v-if="trackMileageSource === 'CITY_THIRD_PARTY'">
                      <span class="source-label">市州</span>
                      <el-select v-model="trackMileageCity" size="small" style="width:130px" filterable
                                 placeholder="选择市州">
                        <el-option v-for="city in cities" :key="city" :label="city" :value="city"></el-option>
                      </el-select>
                    </template>
                  </template>
                </div>
                <div v-if="isCityDirType(moduleSel[g.key])" class="module-file">
                  <div class="tip">无需选文件:自动扫描 docs/投资/输入/…/{{ period ? Number(period.slice(5)) : 'X' }}月 目录下全部市州报表,逐文件容错解析入库(项目主档+月度,含本月完成/建设阶段/形象进度;十五五项目自动标记)。</div>
@@ -59,13 +74,20 @@
                </div>
                <div v-else-if="moduleSel[g.key] && !isDirOnlyType(moduleSel[g.key])" class="module-file">
                  <div class="file-name" :title="fileNamesText(moduleSel[g.key])">{{ fileNamesText(moduleSel[g.key]) || '未选择文件' }}</div>
                  <div v-if="isTrackCity(moduleSel[g.key])" class="tip" style="margin:0 0 6px">同一企业的多个文件、多个页签会合并计算,车牌去重;本次会整体覆盖所选市州同报表期的第三方轨迹里程。审核测算时,孝感规上企业一律采用本市第三方数据,不采用省重载平台;其他市州按“有效轨迹里程÷有轨迹车辆数”择优。</div>
                  <div v-if="moduleSel[g.key] === 'h202'" class="tip" style="margin:0 0 6px">选择文件夹后,自动识别并导入目录内符合 H202 命名规则的全部 .xlsx 文件。</div>
                  <div class="file-btns">
                    <el-upload action="#" :auto-upload="false" :show-file-list="false" multiple :accept="acceptOf(moduleSel[g.key])"
                               :ref="'up' + g.key" :on-change="f => onFilePicked(g.key, f)" style="display:inline-block">
                      <el-button size="mini" type="primary" plain icon="el-icon-folder-opened" :disabled="importing">选择文件</el-button>
                    </el-upload>
                    <input v-if="moduleSel[g.key] === 'h202'" :ref="'folder' + g.key" type="file" webkitdirectory directory multiple accept=".xlsx"
                           style="display:none" @change="onFolderPicked(g.key, $event)">
                    <el-button v-if="moduleSel[g.key] === 'h202'" size="mini" type="primary" icon="el-icon-folder-opened"
                               :disabled="importing" title="选择文件夹后自动批量导入"
                               @click="pickH202Folder(g.key)">选择文件夹并导入</el-button>
                    <el-button size="mini" type="primary" icon="el-icon-upload2" :loading="importing" :disabled="importing || !fileCount(moduleSel[g.key])"
                               @click="importNow(g.key)">{{ fileCount(moduleSel[g.key]) > 1 ? '批量导入 ' + fileCount(moduleSel[g.key]) + ' 个文件' : '立即导入' }}</el-button>
                               @click="importNow(g.key)">{{ importButtonText(moduleSel[g.key]) }}</el-button>
                  </div>
                </div>
              </div>
@@ -198,7 +220,7 @@
import api from '@/api'
import { granularityOfMany, disabledDateFor, granularityHint, snapPeriod } from '@/utils/periodGranularity'
const TYPE_LABELS = {
  h2032: 'H203-2月报', transportAuth: '运政车辆', trackMileage: '轨迹里程', scaleSplit: '规上规下拆分',
  h2032: 'H203-2月报', h202: 'H202车辆拥有情况', transportAuth: '运政车辆', trackMileage: '轨迹里程', scaleSplit: '规上规下拆分',
  freightTurnover: '货运量周转量', passengerMonthly: 'H203-1旅客月报', passengerIndividual: '个体客运量/周转量',
  passengerAuth: '旅客运政车辆数', energyMonthly: 'H204能耗季报', energyAuth: '能耗车辆运政信息',
  investment: '投资月报(客运站场)', investmentLogistics: '投资月报(物流园区)', investmentSystem: '投资系统导出',
@@ -209,10 +231,12 @@
  H2032: 'H203-2月报', H2031: 'H203-1旅客月报', H204: 'H204能耗季报', PASSENGER_AUTH: '旅客运政车辆数',
  PASSENGER_INDIVIDUAL: '个体客运量/周转量', ENERGY_AUTH: '能耗车辆运政信息', TRANSPORT_AUTH: '运政车辆',
  TRACK_MILEAGE: '轨迹里程', SCALE_SPLIT: '规上规下拆分', FREIGHT_TURNOVER: '货运量周转量',
  TRACK_MILEAGE_CITY: '市州第三方轨迹里程',
  INVEST_SYSTEM: '投资系统导出', CITY_BUS: '城市公交月报', CITY_TAXI: '巡游出租月报', CITY_TAXI_AUTH: '出租车运政车辆', WYC_TOTAL: '网约车总数', WYC_ORDER: '网约车订单及全省总量', WYC_ORDER_REPORT: '网约车订单报告'
}
const BATCH_TYPE_MAP = {
  H2032: 'h2032', TRANSPORT_AUTH: 'transportAuth', TRACK_MILEAGE: 'trackMileage',
  H2032: 'h2032', H202: 'h202', TRANSPORT_AUTH: 'transportAuth', TRACK_MILEAGE: 'trackMileage',
  TRACK_MILEAGE_CITY: 'trackMileage',
  SCALE_SPLIT: 'scaleSplit', FREIGHT_TURNOVER: 'freightTurnover',
  H2031: 'passengerMonthly', PASSENGER_AUTH: 'passengerAuth', PASSENGER_INDIVIDUAL: 'passengerIndividual',
  H204: 'energyMonthly', ENERGY_AUTH: 'energyAuth',
@@ -220,6 +244,7 @@
  WYC_TOTAL: 'wycTotal', WYC_ORDER: 'wycOrder', WYC_ORDER_REPORT: 'wycOrderReport',
  INVEST_SYSTEM: 'investmentSystem'
}
const H202_FOLDER_FILE_PATTERN = /^RP_JTB_FreightVehicle_.+\.xlsx$/i
export default {
  components: { AppHeader },
  name: 'DataImport',
@@ -241,6 +266,10 @@
      batchLoading: false,
      moduleSel: { freight: 'h2032', passenger: '', city: '', energy: '', invest: '' },
      activeModule: 'freight',
      trackMileageSource: 'PROVINCIAL',
      trackMileageCity: '',
      cities: ['武汉市', '黄石市', '十堰市', '宜昌市', '襄阳市', '鄂州市', '荆门市', '孝感市', '荆州市', '黄冈市',
        '咸宁市', '随州市', '恩施州', '仙桃市', '潜江市', '天门市', '神农架林区'],
      files: {},
      fileNames: {},
      overview: {},
@@ -248,6 +277,7 @@
        {
          key: 'freight', name: '道路货运', types: [
            { value: 'h2032', label: '道路货物运输月度生产情况' },
            { value: 'h202', label: '公路货物营运车辆拥有情况(H202)' },
            { value: 'transportAuth', label: '运政车辆' },
            { value: 'trackMileage', label: '轨迹里程' },
            { value: 'scaleSplit', label: '规上规下拆分' },
@@ -349,13 +379,14 @@
    templateName() {
      const map = {
        h2032: '模板_交企统H203-2表_道路货物运输月度生产情况.xlsx',
        h202: 'RP_JTB_FreightVehicle_全省.xlsx(导入前将文件名“全省”和表内 L3 报表日期改为实际地区、报表期末日期)',
        transportAuth: '模板_运政车辆.xlsx',
        trackMileage: '模板_轨迹里程.xlsx',
        scaleSplit: '模板_规上规下拆分运输量.xlsx',
        freightTurnover: '模板_货运量周转量.xlsx',
        passengerMonthly: '公路旅客运输月度生产情况.xlsx(含运政车辆数sheet)',
        passengerAuth: '模板_公路旅客运政车辆数.xls(支持 企业代码/企业名称/车辆数/载客位数 与 运政库导出 OWNERNAME/总车辆数/客位数)',
        passengerIndividual: '个体客运量汇总.xlsx(列:所属地区/企业代码/企业名称/个体客运量/个体旅客周转量)',
        passengerIndividual: '模板_个体客运(2026.7).xlsx(标题月份需与报表期一致;列:市州/个体车辆数/个体客运量/个体旅客周转量)',
        energyMonthly: '道路货运车辆能源消耗情况(2026年).xlsx(能耗明细+运政车辆信息两sheet)',
        energyAuth: '模板_能耗车辆运政信息.xlsx(列:车牌号/车辆类型/燃料类型/标记吨位/准牵引质量)',
        investment: '7月客运站投资明细表(市州汇总大表,给领导).xlsx',
@@ -375,13 +406,14 @@
    templateUrl() {
      const map = {
        h2032: '货运/模板_交企统H203-2表_道路货物运输月度生产情况.xlsx',
        h202: '货运/RP_JTB_FreightVehicle_全省.xlsx',
        transportAuth: '货运/模板_运政车辆.xlsx',
        trackMileage: '货运/模板_轨迹里程.xlsx',
        scaleSplit: '货运/模板_规上规下拆分运输量.xlsx',
        freightTurnover: '货运/模板_货运量周转量.xlsx',
        passengerMonthly: '公路旅客/模板_交企统H203-1表_公路旅客运输月度生产情况.xlsx',
        passengerAuth: '公路旅客/模板_公路旅客运政车辆数.xls',
        passengerIndividual: '公路旅客/个体客运量汇总.xlsx',
        passengerIndividual: '公路旅客/模板_个体客运(2026.7).xlsx',
        energyMonthly: '能耗/模板_道路货运车辆能源消耗情况(2026).xlsx',
        energyAuth: '能耗/模板_能耗车辆运政信息.xlsx',
        cityBus: '城市客运/生成_城市公交客运量分市州明细.xlsx',
@@ -430,6 +462,24 @@
    onModuleChange(key) {
      this.importType = this.moduleSel[key] || ''
    },
    onTrackSourceChange() {
      this.clearTrackMileageFiles()
    },
    isTrackCity(type) {
      return type === 'trackMileage' && this.trackMileageSource === 'CITY_THIRD_PARTY'
    },
    importButtonText(type) {
      const count = this.fileCount(type)
      if (this.isTrackCity(type)) return count > 1 ? '合并导入 ' + count + ' 个文件' : '合并导入'
      return count > 1 ? '批量导入 ' + count + ' 个文件' : '立即导入'
    },
    clearTrackMileageFiles() {
      this.$set(this.files, 'trackMileage', [])
      this.$set(this.fileNames, 'trackMileage', [])
      const refs = this.$refs.upfreight
      const up = Array.isArray(refs) ? refs[0] : refs
      if (up && up.clearFiles) up.clearFiles()
    },
    onModuleSwitch() {
      this.importType = this.moduleSel[this.activeModule] || ''
    },
@@ -437,6 +487,7 @@
    endpoint(t) {
      const map = {
        h2032: '/import/h2032',
        h202: '/import/h202',
        transportAuth: '/import/transportAuth',
        trackMileage: '/import/trackMileage',
        scaleSplit: '/import/scaleSplit',
@@ -457,6 +508,37 @@
        wycOrderReport: '/import/wycOrderReport'
      }
      return map[t] || ''
    },
    pickH202Folder(key) {
      if (this.importing) { this.$message.warning('正在导入中,请稍候再选择文件夹'); return }
      if (!this.period) { this.$message.warning('请先选择报表期'); return }
      const ref = this.$refs['folder' + key]
      const input = Array.isArray(ref) ? ref[0] : ref
      if (!input) { this.$message.error('文件夹选择控件未就绪,请刷新页面后重试'); return }
      input.value = ''
      input.click()
    },
    onFolderPicked(key, event) {
      const input = event && event.target
      const selected = Array.from((input && input.files) || [])
      if (input) input.value = ''
      const type = this.moduleSel[key]
      if (type !== 'h202' || !selected.length) return
      if (this.importing) { this.$message.warning('正在导入中,请稍候再选择文件夹'); return }
      if (!this.period) { this.$message.warning('请先选择报表期'); return }
      const fileList = selected
        .filter(f => H202_FOLDER_FILE_PATTERN.test(f.name))
        .sort((a, b) => String(a.webkitRelativePath || a.name).localeCompare(String(b.webkitRelativePath || b.name), 'zh-CN'))
      const ignored = selected.length - fileList.length
      if (!fileList.length) {
        this.$message.warning('所选文件夹中没有符合 H202 命名规则的 .xlsx 文件')
        return
      }
      this.$set(this.files, type, fileList)
      this.$set(this.fileNames, type, fileList.map(f => f.name))
      if (ignored > 0) this.$message.warning('已忽略 ' + ignored + ' 个不符合 H202 命名规则的文件')
      this.importing = true
      this.batchImport(type, key, fileList).finally(() => { this.importing = false })
    },
    onFilePicked(key, file) {
      const type = this.moduleSel[key]
@@ -482,6 +564,16 @@
      if (!fileList.length) { this.$message.warning('请先为该类型选择文件'); return }
      if (!this.period) { this.$message.warning('请先选择报表期'); return }
      if (this.importing) { this.$message.warning('正在导入中,请稍候…'); return }
      if (this.isTrackCity(type)) {
        if (!this.trackMileageCity) { this.$message.warning('请先选择市州'); return }
        this.importing = true
        this.importCityTrackMileage(fileList).finally(() => { this.importing = false })
        return
      }
      if (type === 'trackMileage' && fileList.length > 1) {
        this.$message.warning('省重载平台轨迹里程一次只能导入 1 个文件;多个文件合并请选择“市州第三方”。')
        return
      }
      this.importing = true
      if (fileList.length > 1 || type === 'investment' || type === 'investmentLogistics') {
        this.batchImport(type, key, fileList).finally(() => { this.importing = false })
@@ -517,6 +609,36 @@
    fileNamesText(type) {
      const list = this.fileNames[type] || []
      return list.length ? '已选 ' + list.length + ' 个文件:' + list.join('、') : ''
    },
    importCityTrackMileage(fileList) {
      const fd = new FormData()
      fd.append('period', this.period)
      fd.append('city', this.trackMileageCity)
      fileList.forEach(f => fd.append('files', f))
      this.$message({ message: '正在合并导入 ' + fileList.length + ' 个市州轨迹文件…', duration: 3000 })
      return api.post('/import/trackMileageCity', fd, { timeout: 600000 })
        .then(res => {
          if (res && res.code !== undefined && res.code !== 200) {
            this.showResultDialog({
              title: '市州第三方轨迹里程导入失败',
              html: this.escapeHtml(res.message || '导入失败').replace(/\n/g, '<br>'),
              level: 'error'
            })
            return
          }
          this.$message.success((res && res.data) || '市州第三方轨迹里程导入成功')
          this.afterImport()
          this.clearTrackMileageFiles()
        })
        .catch(e => {
          if (e && e._toast) return
          const message = (e.response && e.response.data && e.response.data.message) || e.message || '导入失败'
          this.showResultDialog({
            title: '市州第三方轨迹里程导入失败',
            html: this.escapeHtml(message).replace(/\n/g, '<br>'),
            level: 'error'
          })
        })
    },
    batchImport(type, key, fileList) {
      if (!this.period) { this.$message.warning('请先选择报表期'); return }
@@ -876,6 +998,7 @@
.card-head { font-weight: 600; margin-bottom: 6px; }
.module-sel { max-width: 1100px; }
.module-sel-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.source-label { font-size: 13px; color: #606266; font-weight: 600; white-space: nowrap; }
.tpl-box { display: flex; align-items: center; gap: 8px; min-width: 0; color: #606266; font-size: 13px; }
.tpl-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 480px; }
.group-label { font-size: 13px; color: #606266; font-weight: 600; margin-bottom: 6px; padding-left: 6px; border-left: 3px solid #409EFF; }