anonResultAnalysis.vue 41.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
<template>
  <div style="display: flex;justify-content: center;width: 100%;">
    <div v-show="!isWordStyle" class="analysis-result-main">
       <div class="reject" v-show="analysisResultInfo.rating <= 2">
      <div v-if="analysisResultInfo.rating == 2" class="header_title">
        <span class="title_text">{{ `匿名化评测结果不符合评测要求,等级为${analysisResultInfo.rating}级,重标识符风险大于风险阈值0.05,请对如性别、年龄、地区等准标识符加大泛化以降低重标识风险。` }}</span>
      </div>
       <div v-else class="header_title">
        <span class="title_text">{{ `匿名化评测结果不符合评测要求,等级为${analysisResultInfo.rating}级,数据中仍含可直接识别个人身份的信息,请对该信息进行脱敏处理。点击下载`}}</span>
        <span class="title_text link" @click="downErrorFile">《需修正文件明细表》</span>
      </div>
    </div>
      <div v-if="showTitle" class="result-title">匿名结果分析</div>
      <div class="kpi-content" v-show="Object.keys(analysisResultInfo).length > 0">
        <div class="border-content">
          <div class="text">去标识化效果评估结果</div>
          <span class="number score-color">{{ analysisResultInfo.rating + '级' }}</span>
        </div>
        <div class="border-content">
          <span class="text">重标识风险最大值<el-tooltip placement="top" effect="light" popper-class="table_tooltip">
              <template #content>
                <div style="max-width: 236px;">
                  所有等价类的重标识风险最大值
                </div>
              </template>
              <el-icon style="margin-left: 2px;margin-top: 2px;">
                <QuestionFilled />
              </el-icon>
            </el-tooltip></span>
          <span class="number">{{ analysisResultInfo.reIdentifyRiskRb != null ?
            (analysisResultInfo.reIdentifyRiskRb || 0) : '--'
          }}</span>
        </div>
        <div class="border-content">
          <span class="text">重标识风险平均值<el-tooltip placement="top" effect="light" popper-class="table_tooltip">
              <template #content>
                <div style="max-width: 236px;">
                  所有等价类的重标识风险平均值
                </div>
              </template>
              <el-icon style="margin-left: 2px;margin-top: 2px;">
                <QuestionFilled />
              </el-icon>
            </el-tooltip></span>
          <span class="number">{{ analysisResultInfo.reIdentifyRiskRc != null ?
            (analysisResultInfo.reIdentifyRiskRc || 0) : '--' }}</span>
        </div>
        <div class="border-content">
          <span class="text">环境重标识攻击概率<el-tooltip placement="top" effect="light" popper-class="table_tooltip">
              <template #content>
                <div style="max-width: 236px;">
                  完全公开共享数据发布,攻击者对数据集进行环境重标识攻击的概率为1。领地公开共享与受控公开共享数据发布,环境重标识攻击概率为内部故意攻击概率、数据集包含熟人概率和数据泄露概率三者的最大值。
                </div>
              </template>
              <el-icon style="margin-left: 2px;margin-top: 2px;">
                <QuestionFilled />
              </el-icon>
            </el-tooltip></span>
          <span class="number">{{ analysisResultInfo.envReAttackPr != null ?
            (analysisResultInfo.envReAttackPr || 0) : '--' }}</span>
        </div>
        <div class="border-content">
          <span class="text">等价类门限风险<el-tooltip placement="top" effect="light" popper-class="table_tooltip">
              <template #content>
                <div style="max-width: 236px;">
                  完全公开共享数据发布,门限阈值取值1/20;受控公开共享数据发布,门限阈值取值1/5;领地公开共享数据发布,门限阈值取值1/3;等价类门限风险为:等价类的重标识风险大于门限阈值为1,小于等于为0,求和后除以等价类个数。
                </div>
              </template>
              <el-icon style="margin-left: 2px;margin-top: 2px;">
                <QuestionFilled />
              </el-icon>
            </el-tooltip></span>
          <span class="number">{{ analysisResultInfo.reIdentifyRiskRa != null ?
            (analysisResultInfo.reIdentifyRiskRa || 0) : '--' }}</span>
        </div>
        <div class="border-content">
          <span class="text">重标识风险总体风险<el-tooltip placement="top" effect="light" popper-class="table_tooltip">
              <template #content>
                <div style="max-width: 236px;">
                  完全公开共享,当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险最大值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1
                  受控公开共享和领地公开共享,当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险平均值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1
                  <!-- {{ oldAnonTaskValueInfo.dataSharingTypeCode == '01' ? '完全公开共享,当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险最大值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1。'
                       : `${oldAnonTaskValueInfo.dataSharingTypeCode == '02' ? '受控公开共享' : '领地公开共享'},当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险平均值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1。` }} -->
                </div>
              </template>
              <el-icon style="margin-left: 2px;margin-top: 2px;">
                <QuestionFilled />
              </el-icon>
            </el-tooltip></span>
          <span class="number">{{ analysisResultInfo.reIdentifyOverallRisk != null ?
            (analysisResultInfo.reIdentifyOverallRisk || 0) : '--' }}</span>
        </div>
        <div class="border-content">
          <span class="text">重标识可接受风险阈值</span>
          <span class="number">{{ oldAnonTaskValueInfo.anonPrivacyMode?.riskThreshold == null ? 0.05 :
            (oldAnonTaskValueInfo.anonPrivacyMode?.riskThreshold || 0) }}</span>
        </div>
      </div>
      <div class="result-title">重标识风险表</div>
      <el-table ref="tableRef" v-show="analysisResultTableFields.length" :data="resultData"
        v-loading="analysisResultLoading" :highlight-current-row="true" stripe border tooltip-effect="light"
        height="100%" row-key="guid" :style="{ width: '100%', height: '280px' }">
        <el-table-column label="等价类" type="index" width="68px" align="center" show-overflow-tooltip>
          <template #default="scope">
            <span>{{
              pageInfo.curr !== undefined
                ? (pageInfo.curr - 1) * pageInfo.limit + scope.$index + 1
                : scope.$index + 1
            }}</span>
          </template>
        </el-table-column>
        <template v-for="(item, index) in (analysisResultTableFields || [])">
          <el-table-column :label="item.chName" :width="item.dataType === 'datetime'
            ? TableColumnWidth.DATETIME
            : item.dataType === 'date'
              ? TableColumnWidth.DATE
              : originResultTableFieldColumn[item.enName]
            " :align="getTextAlign(item)" :header-align="getTextAlign(item)"
            :formatter="(row) => formatterPreviewDate(row, item)" :show-overflow-tooltip="true">
          </el-table-column>
        </template>
        <el-table-column label="等价类大小" prop="equivalenceClassNum" width="98" align="right" fixed="right"
          show-overflow-tooltip></el-table-column>
        <el-table-column label="重标识风险" prop="reIdentifyRisk" width="96" align="right" fixed="right"
          show-overflow-tooltip></el-table-column>
        <el-table-column label="判断重风险是否大于门限阈值" prop="isGtThreshold" width="150" align="left" fixed="right"
          show-overflow-tooltip></el-table-column>
      </el-table>
      <div v-show="!analysisResultTableFields.length" class="empty-content">
        <img src="../../../assets/images/empty-data.png" :style="{ width: '168px', height: '96px' }" />
        <div class="empty-text">暂无数据</div>
      </div>
      <div v-show="analysisResultTableFields.length" class="result-table-desc">门限阈值的取值:完全公开共享数据发布,取值1/20;受控公开共享数据发布,取值1/5;领地公开共享数据发布,取值1/3</div>
      <PageNav v-show="analysisResultTableFields.length" :class="[pageInfo.type]" :pageInfo="pageInfo"
        @pageChange="pageChange" />
      <div class="row-two-main" style="margin-top: 12px;">
        <div class="table-one">
          <div class="result-title">对抗性测试关键变量</div>
          <el-table ref="varTableRef" :data="analysisResultInfo?.adversarialTest || []" :highlight-current-row="true"
            stripe border tooltip-effect="light" height="100%" row-key="guid"
            :style="{ height: oldAnonTaskValueInfo.dataSharingTypeCode != '01' ? (containerWidth > 1397 ? '378px' : (containerWidth < 1048 ? '414px' : '396px')) : 'auto' }">
            <el-table-column label="序号" type="index" width="56px" align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="数据项" prop="chName" width="150px" align="left"
              show-overflow-tooltip></el-table-column>
            <el-table-column label="唯一性分值" prop="uniqueScore" width="110px" align="right"
              show-overflow-tooltip></el-table-column>
            <el-table-column label="影响力分值" prop="influenceScore" width="110" align="right"
              show-overflow-tooltip></el-table-column>
            <el-table-column label="数据属性标识度分值" prop="dataAttrIdentScore" width="160" align="right"
              show-overflow-tooltip></el-table-column>
          </el-table>
        </div>
        <div class="table-two" v-show="oldAnonTaskValueInfo.dataSharingTypeCode != '01'">
          <div class="result-title">内部故意攻击概率</div>
          <div class="desc" style="margin-bottom: 4px;color: #999;line-height: 18px;">
            重标识数据的动机和能力为低,从重标识攻击可能性分析表可得出在内部攻击方面,重标识攻击概率的取值为0.05。</div>
          <el-table ref="innerTableRef" :data="innerResultData" :highlight-current-row="true" stripe border
            tooltip-effect="light" height="100%" row-key="guid" :style="{ height: '356px' }"
            :span-method="arrayInnerSpanMethod" :cell-class-name="handleInnerCellClass">
            <!-- <el-table-column label="序号" type="index" width="56px" align="center" show-overflow-tooltip>
                  </el-table-column> -->
            <el-table-column label="风险减缓控制水平" prop="level" width="150px" align="left"
              show-overflow-tooltip></el-table-column>
            <el-table-column label="动机和能力" prop="competencyLevel" width="140px" align="left"
              show-overflow-tooltip></el-table-column>
            <el-table-column label="重标识攻击概率" prop="value" width="140" align="right" show-overflow-tooltip>
              <template #default="scope">
                <span>{{ scope.row.value }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="row-two-main" v-show="oldAnonTaskValueInfo.dataSharingTypeCode != '01'">
        <div class="table-one border">
          <div class="result-title">数据集包含熟人概率</div>
          <div class="result-title-h1">pr=1-1-p^m</div>
          <div class="result-title-desc">
            {{ ` 数据集包含熟人概率可通过以上公式计算,${new
              Date().getFullYear()}年我国最新的人口统计为${analysisResultInfo?.allPerson ||
              0}亿人,其中该数据集的容量为${analysisResultInfo?.dataSetNum || 0}万,
            占总人口的比例为${analysisResultInfo.patientPopulationRate ||
              0}%,m值取推荐值150,数据集包含熟人的概率为${analysisResultInfo.randomAcquaintancePr || 0}。` }}
          </div>
        </div>
        <div class="table-two border">
          <div class="result-title">数据泄露概率</div>
          <div class="result-title-desc">
            <div>对于安全和隐私控制能力评估为低的情况。推荐将数据泄露概率设定为0.55</div>
            <div>对于安全和隐私控制能力评估为中的情况,推荐将数据泄露概率设定为0.27</div>
            <div>对于安全和隐私控制能力评估为高的情况,推荐将数据泄露概率设定为 0.14</div>
            <div>{{ `数据接收方的安全和隐私控制能力为高,按照推荐值将数据泄露概率设定为${analysisResultInfo.dataBreachPr || 0}。` }}</div>
          </div>
        </div>
      </div>
    </div>
  <div v-show="isWordStyle" class="analysis-result-main report-main" ref="report">
  <!-- 报告总览 -->
  <h1 class="MsoHeading1" style="text-align: left;margin-top: 10px;margin-bottom: 10px;">报告总览</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `一、评价对象:${analysisResultInfo.tenantName}2025年1月1日至2025年12月31日的${oldAnonTaskValueInfo.taskName},该数据集包含1张表,字段总数量共计${changeNum(analysisResultInfo.fieldNum || 0)}个,记录总数量共计${changeNum(analysisResultInfo.dataSetRecord || 0)}条,数据元素总量为${changeNum(analysisResultInfo.dataTotal || 0)}个 。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `二、评价方法:基于匿名化评估国家标准GB/T 42460-2023《信息安全技术 个人信息去标识化效果评估指南》、GB/T 37964-2019《信息安全技术 个人信息去标识化指南》,以及《中华人民共和国个人信息保护法》、《中华人民共和国数据安全法》、《中华人民共和国网络安全法》、《面向数据流通的匿名化效果实施指南 草案》、《面向数据流通的匿名化效果评估指南 草案》和《数据安全技术 个人信息匿名化处理指南及评价方法 征求意见稿》相关法律法规,采用“定性分析”与“定量计算”相结合的综合评估方法。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `三、评估结论:综合定性与定量评估结果,根据GB/T 42460-2023的分级标准,该${oldAnonTaskValueInfo.taskName}的匿名化效果评定为${analysisResultInfo.rating}级${analysisResultInfo.rating <=2 ? '(重标识风险较高)' : ''}。${`需要对准标识符${analysisResultInfo.qualifiedIdentifier?.map(f => f.chName)?.join('、')}做有效的泛化和抑制,满足k-匿名要求(设定k10),从而使得该数据集适用于受控环境下进行跨机构流通。`}` }}</p>
  <br clear="all" style="page-break-before:always;mso-break-type:section-break">
  <h1 class="MsoHeading1" style="text-align: left;margin-top: 10px;margin-bottom: 10px;">一、评估基本信息</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估项目名称:${oldAnonTaskValueInfo.taskName}匿名化效果评估` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估对象:${analysisResultInfo.tenantName}2025年1月1日至2025年12月31日的${oldAnonTaskValueInfo.taskName}(共计${changeNum(analysisResultInfo.dataSetRecord || 0)}条记录)` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估依据:GB/T 42460-2023《信息安全技术 个人信息去标识化效果评估指南》、GB/T 37964-2019《信息安全技术 个人信息去标识化指南》、《中华人民共和国个人信息保护法》、《中华人民共和国数据安全法》、《中华人民共和国网络安全法》、《面向数据流通的匿名化效果实施指南 草案》、《面向数据流通的匿名化效果评估指南 草案》和《数据安全技术 个人信息匿名化处理指南及评价方法 征求意见稿》。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估日期:${analysisResultInfo.execTime ? analysisResultInfo.execTime.substring(0, 10) : ''}` }}</p>
  <!-- 2. 评估准备 -->
  <h1 class="MsoHeading1" style="text-align: left;margin-top: 10px;margin-bottom: 10px;">二、评估准备</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `数据集与环境确认:待评估数据集包含${analysisResultInfo?.column?.slice(0, 4)?.map(f => f.chName).join('、')}${analysisResultInfo?.column?.length > 4 ? '等字段' : '字段'}。数据将用于跨机构的科学研究,处于半开放网络环境。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `风险阈值设定:结合科研数据共享需求,设定可接受的重标识风险阈值为0.05(即5%)。` }}</p>

  <!-- 3. 定性评估 -->
  <h1 style="text-align: left;margin-top: 10px;margin-bottom: 10px;">三、定性评估</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `依据GB/T 37964标准,对数据集中的标识符进行了识别与分类处理:` }}</p>
  
  <p style="margin: 0px;white-space: pre-wrap;font-weight: 700;margin: 8px 0px;text-indent: 2em;">{{ `1.直接标识符处理` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `识别字段:姓名、身份证号、手机号、住院号、家庭详细住址等。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '处理措施:采用完全删除技术。' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估结果:数据集中已完全消除直接标识符,无法通过单一字段直接识别特定患者。` }}</p>

  <p style="margin: 0px;white-space: pre-wrap;font-weight: 700;margin: 8px 0px;text-indent: 2em;">{{ `2.准标识符处理` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `识别字段:性别、年龄、职业、入院日期、出院日期、出生日期、婚姻、受教育水平等。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '处理措施:' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `时间泛化:将精确的“入院日期”、“出院日期”泛化为“年份”或住院天数、“年龄”泛化为“年龄段”(如将年龄转换为[40-50]区间)。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `对准标识符的泛化确保同一属性组合(相同的准标识符)下的记录数满足k-匿名要求(设定k≥10)。比如性别为男、年龄[40-50]、职业为其他、入院时间为2025年11月,出院时间为2025年11月的记录数满足10条以上。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `评估结果:数据集中未对准标识符进行有效地泛化和抑制处理。` }}</p>

  <!-- 4. 定量评估(重标识风险计算) -->
  <h1 style="text-align: left;margin-top: 10px;margin-bottom: 10px;">四、定量评估(重标识风险计算)</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `依据GB/T 42460-2023《信息安全技术个人信息去标识化效果评估指南》附录D,对去标识化以后的数据集基于K匿名模型进行去标识化效果的评估。总体方案为先对所有的数据进行直接标识符识别,判断无直接标识符内容后,再计算数据集每行记录、整体数据集的重标识风险,进而计算环境重标识攻击概率,最后再结合环境重标识攻击概率计算整个数据集的重标识整体风险。` }}</p>
  
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;"><strong>{{ `直接标识符:` }}</strong>{{ '经扫描数据集的内容,比如现病史、既往史等长文本字段进行扫描,未发现直接标识符内容。' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;"><strong>{{ `重标识风险总体风险:` }}</strong>{{  `准标识符${analysisResultInfo.rating > 2 ? '' : '并未'}进行有效泛化,计算的重标识符总体风险为${analysisResultInfo.reIdentifyOverallRisk != null ?
            (analysisResultInfo.reIdentifyOverallRisk || 0) * 100 : '--'}${analysisResultInfo.reIdentifyOverallRisk ? '%' : ''};` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;"><strong>{{ `重标识风险最大值:` }}</strong>{{ `计算数据集中重标识风险最高的记录所对应的风险值。经计算,该数据集最大重标识风险值为${analysisResultInfo.reIdentifyRiskRb != null ?
            (analysisResultInfo.reIdentifyRiskRb || 0) : '--'}${analysisResultInfo.reIdentifyRiskRb ? `(即${analysisResultInfo.reIdentifyRiskRb*100}%)` : ''}。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;"><strong>{{ `重标识风险平均值:` }}</strong>{{ `模拟攻击者随机抽取一条记录并尝试重标识的平均风险。经计算,该数据集重标识风险的平均值为${analysisResultInfo.reIdentifyRiskRc != null ?
            (analysisResultInfo.reIdentifyRiskRc || 0) : '--'}${analysisResultInfo.reIdentifyRiskRc ? `(即${analysisResultInfo.reIdentifyRiskRc * 100}%)` : ''}。` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;"><strong>{{ `环境重标识攻击概率:` }}</strong>{{ oldAnonTaskValueInfo.dataSharingTypeCode == '01' ? `${oldAnonTaskValueInfo.dataSharingTypeName}的数据集,攻击者对数据集进行环境重标识攻击的概率为1。即该数据集的攻击概率为${analysisResultInfo.envReAttackPr != null ?
            (analysisResultInfo.envReAttackPr || 0) : '--'}${analysisResultInfo.envReAttackPr ? `(即${analysisResultInfo.envReAttackPr * 100}%)` : ''}。` : 
  `${oldAnonTaskValueInfo.dataSharingTypeName}的数据集,环境重标识攻击概率为内部故意攻击概率、数据集包含熟人概率和数据泄露概率三者的最大值,经计算,该数据集的攻击概率为${analysisResultInfo.envReAttackPr != null ?
            (analysisResultInfo.envReAttackPr || 0) : '--'}${analysisResultInfo.envReAttackPr ? `(即${analysisResultInfo.envReAttackPr * 100}%)` : ''}。` }}</p>
  
  <p style="margin: 8px 0px 4px;white-space: pre-wrap;font-weight: 700;text-indent: 2em;">{{ '具体计算指标如下:' }}</p>

  <!-- 1. 重标识风险表 -->
  <p style="display: block;white-space: pre-wrap;font-weight: 700;margin: 8px 0px 4px;text-indent: 2em;">{{ '1. 重标识风险表' }}</p>
  <p style="display: block;margin-bottom: 4px;white-space: pre-wrap;text-indent: 2em;">{{ `门限阈值的取值:该数据集为${oldAnonTaskValueInfo.dataSharingTypeName}数据,门限阈值为${oldAnonTaskValueInfo.dataSharingTypeCode == '01' ? '1/20' : (oldAnonTaskValueInfo.dataSharingTypeCode == '02' ? '1/5' : '1/3')} ` }}</p>
    <table border="0" cellspacing="0"
        style="width:100%;word-break: break-all;margin: 0 auto;text-align: center;border-collapse: collapse;color: #212121">
        <thead>
          <tr>
            <th v-for="(item, index) in resultTableFields" :key="index" style="border: 0.5px solid #d9d9d9">
              <span>{{ item.chName }}</span>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(recordItem, j) in fullResultData" :key="j">
            <td v-for="(columnItem, i) in resultTableFields" :key="i"
              :style="{ border: '0.5px solid #d9d9d9', 'text-align': <any>(getTextAlign(columnItem) ?? 'left') }">
              <span :style="{ 'word-break': 'break-all' }">
                {{ columnItem.enName == 'index' ? (j + 1) : formatterPreviewDate(recordItem, columnItem) }}
              </span>
            </td>
          </tr>
        </tbody>
      </table>

  <!-- 2. 内部故意攻击概率 -->
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;font-weight: 700;margin: 8px 0px 4px;text-indent: 2em;">{{ '2. 内部故意攻击概率'}}</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;margin-bottom: 4px;white-space: pre-wrap;text-indent: 2em;">{{ '重标识数据的动机和能力为低,从重标识攻击可能性分析表可得出在内部攻击方面,重标识攻击概率的取值为0.05。' }}</p>
  <table v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" border="0" cellspacing="0"
        style="width:100%;word-break: break-all;margin: 0 auto;text-align: center;border-collapse: collapse;color: #212121;">
        <thead>
          <tr>
            <th v-for="(item, index) in innerResultFields" :key="index" style="border: 0.5px solid #d9d9d9">
              <span>{{ item.label }}</span>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(recordItem, j) in innerResultData" :key="j">
            <template v-for="(columnItem, i) in innerResultFields" :key="i">
              <td :rowspan="i == 0 ? 3 : 1" v-if="!(j % 3 != 0 && i == 0)"
                :style="{ border: '0.5px solid #d9d9d9', 'text-align': <any>(columnItem.align ?? 'left') }">
                <span :style="{ 'word-break': 'break-all' }">
                  {{ recordItem[columnItem.field] }}
                </span>
              </td>
            </template>
          </tr>
        </tbody>
      </table>

  <!-- 3. 数据集包含熟人概率 -->
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;font-weight: 700;margin: 8px 0px;white-space: pre-wrap;text-indent: 2em;">{{ '3. 数据集包含熟人概率'}}</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="text-align: center; display: block;font-weight: 700">pr=1-(1-p)^m</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;text-indent: 2em;">
    {{ `数据集包含熟人概率可通过以上公式计算,${new Date().getFullYear()}年我国最新的人口统计为${analysisResultInfo?.allPerson ||
          0}亿人,其中该数据集的容量为${analysisResultInfo?.dataSetNum || 0}万,占总人口的比例为${analysisResultInfo.patientPopulationRate ||
          0}%m值取推荐值150,数据集包含熟人的概率为${analysisResultInfo.randomAcquaintancePr || 0}。` }}
  </p>

  <!-- 4. 数据泄露概率 -->
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;font-weight: 700;margin: 8px 0px;white-space: pre-wrap;text-indent: 2em;">{{ '4. 数据泄露概率'}}</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;text-indent: 2em;">{{ '对于安全和隐私控制能力评估为低的情况,推荐将数据泄露概率设定为0.55。' }}</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;text-indent: 2em;">{{ '对于安全和隐私控制能力评估为中的情况,推荐将数据泄露概率设定为0.27。' }}</p>
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;text-indent: 2em;">{{ '对于安全和隐私控制能力评估为高的情况,推荐将数据泄露概率设定为0.14。' }}</p> 
  <p v-if="oldAnonTaskValueInfo.dataSharingTypeCode != '01'" style="display: block;white-space: pre-wrap;text-indent: 2em;">{{ `数据接收方的安全和隐私控制能力为高,按照推荐值将数据泄露概率设定为${analysisResultInfo.dataBreachPr || 0}。` }}</p>

<!-- 对抗性测试 (评级>=3时展示) -->
 <p v-if="analysisResultInfo.rating >= 3" style="display: block;font-weight: 700;margin: 8px 0px;white-space: pre-wrap;text-indent: 2em;">{{ oldAnonTaskValueInfo.dataSharingTypeCode != '01' ? '5. 对抗性测试' : '2. 对抗性测试' }}</p>
  <p v-if="analysisResultInfo.rating >= 3" style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '依据《数据安全技术个人信息匿名化处理指南及评价方法(征求意见稿)》4.2,去标识化的数据集达到3级可展开对数据级的对抗性测试和不可复原性核验。对抗性测试关键变量如下表:' }}</p>
  <table border="0" cellspacing="0" v-if="analysisResultInfo.rating >= 3" style="width:100%;word-break: break-all;margin: 4px auto 0px auto;text-align: center;border-collapse: collapse;color: #212121;">
    <thead>
      <tr>
        <th v-for="(item, index) in adversarialTestFields" :key="index" style="border: 0.5px solid #d9d9d9">
          <span>{{ item.label }}</span>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(recordItem, j) in analysisResultInfo?.adversarialTest || []" :key="j">
        <td v-for="(columnItem, i) in adversarialTestFields" :key="i" :style="{ border: '0.5px solid #d9d9d9', 'text-align': <any>(columnItem.align ?? 'left') }">
          <span :style="{ 'word-break': 'break-all' }">
            {{ columnItem.field == 'index' ? (j + 1) : recordItem[columnItem.field] === 0 ? 0 : (recordItem[columnItem.field] || '--') }}
          </span>
        </td>
      </tr>
    </tbody>
  </table>
  <p v-if="analysisResultInfo.rating >= 3" style="margin: 4px 0px 0px;white-space: pre-wrap;text-indent: 2em;">{{ '通过识别关键变量,选择标识度高于0.5的属性作为攻击测试的关键变量,在攻击测试中,涉及到的攻击场景,其重标识概率均远小于所接受的风险水平0.05。另外,未发现任何其它可能的安全性问题。' }}</p>

  <!-- 指标说明 -->
  <p style="display: block;font-weight: 700;margin: 8px 0px;white-space: pre-wrap;text-indent: 2em;">{{ '指标说明:'}}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '重标识风险最大值:所有等价类的重标识风险最大值;' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '重标识风险平均值:所有等价类的重标识风险平均值;' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '环境重标识攻击概率:完全公开共享数据发布,攻击者对数据集进行环境重标识攻击的概率为1。领地公开共享与受控公开共享数据发布,环境重标识攻击概率为内部故意攻击概率、数据集包含熟人概率和数据泄露概率三者的最大值;' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '等价类门限风险:完全公开共享数据发布,门限阈值取值1/20;受控公开共享数据发布,门限阈值取值1/5;领地公开共享数据发布,门限阈值取值1/3;等价类门限风险为:等价类的重标识风险大于门限阈值为1,小于等于为0,求和后除以等价类个数;' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '重标识风险总体风险:完全公开共享,当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险最大值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1。' }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ '受控公开共享和领地公开共享,当等价类门限风险=0时,重标识风险总体风险公式为等价类重标识风险平均值*环境重标识攻击概率;当等价类门限风险!=0时,重标识风险总体风险为1。' }}</p>

  <!-- 5. 评估结论与分级 -->
  <h1 style="text-align: left;margin-top: 10px;margin-bottom: 10px;">五、评估结论与分级</h1>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `定性评估结论:${analysisResultInfo.rating == 2 ? '数据集已消除所有直接标识符,但未对准标识符进行了有效的泛化与抑制处理。' : (analysisResultInfo.rating == 4 ? '数据集无任何的直接标识符和准标识符。' : '数据集已消除所有直接标识符,并对准标识符进行了有效的泛化与抑制处理。')}` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `定量评估结论:${analysisResultInfo.rating == 2 ? '数据集的重标识风险总体风险(1)大于预设的可接受风险阈值(0.05)。' : (analysisResultInfo.rating == 4 ? '数据集重标识风险总体风险为0。' : '数据集的重标识风险总体风险(1)小于等于预设的可接受风险阈值(0.05)。')}` }}</p>
  <p style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `最终评级:综合定性与定量评估结果,根据GB/T 42460-2023的分级标准,该${oldAnonTaskValueInfo.taskName}的匿名化效果评定为${analysisResultInfo.rating}级${analysisResultInfo.rating <=2 ? '(重标识风险较高)' : ''}。` }}</p>
  
  <!-- 6. 建议与改进 -->
  <h1 v-if="analysisResultInfo.rating <= 2" style="text-align: left;margin-top: 10px;margin-bottom: 10px;">六、建议与改进</h1>
  <p v-if="analysisResultInfo.rating <= 2" style="margin: 0px;white-space: pre-wrap;text-indent: 2em;">{{ `需要对准标识符${analysisResultInfo.qualifiedIdentifier?.map(f => f.chName)?.join('、')}做有效的泛化和抑制,满足k-匿名要求(设定k10),从而使得该数据集适用于受控环境下进行跨机构流通。` }}</p>
  <br clear="all" style="page-break-before:always;mso-break-type:section-break">
</div>
  </div>
</template>
<script lang="ts" setup name="anonResultAnalysis">
import { TableColumnWidth } from '@/utils/enum';
import { QuestionFilled, CircleCloseFilled } from "@element-plus/icons-vue";
import Moment from 'moment';
import {
  downDicomPath,
} from '@/api/modules/dataAnonymization';
import { changeNum, download } from '@/utils/common';
import { ElMessage } from 'element-plus';

const props = defineProps({
  isWordStyle: { //显示的是否是word报告的样式
    type: Boolean,
    default: false,
  },
  showTitle: {
    type: Boolean,
    default: false,
  },
  analysisResultInfo: {
    type: Object,
    default: {},
  },
  pageInfo: {
    type: Object,
    default: {},
  },
  analysisResultLoading: {
    type: Boolean,
    default: false,
  },
  oldAnonTaskValueInfo: {
    type: Object,
    default: {},
  },
  resultData: { //分页后的数据
    type: Array,
    default: []
  },
  fullResultData: { //全部数据,下载word时使用。
    type: Array,
    default: []
  },
  analysisResultTableFields: {
    type: Array,
    default: [],
  },
  originResultTableFieldColumn: {
    type: Object,
    default: {},
  },
  containerWidth: {
    type: Number,
    default: 1200,
  },
})

const report = ref();

const resultTableFields = computed(() => {
  let arr: any[] = [{ chName: '等价类', dataType: 'int', enName: 'index' }]
  return arr.concat(props.analysisResultTableFields).concat([{
    chName: '等价类大小',
    enName: 'equivalenceClassNum',
    dataType: 'int'
  }, {
    chName: '重标识风险',
    enName: 'reIdentifyRisk',
    dataType: 'decimal'
  }, {
    chName: '判断重风险是否大于门限阈值',
    enName: 'isGtThreshold',
    dataType: 'text'
  }]);
})

const emits = defineEmits([
  "pageChange"
]);

const getTextAlign = (field) => {
  if (field.enName === 'index') {
    return 'center';
  }
  if (field.dataType === 'decimal' || field.dataType === 'int') {
    return 'right';
  }
  return 'left'
}

const formatterPreviewDate = (row, info) => {
  let enName = info.enName;
  let v = row[enName];
  if (v === 0) {
    return v;
  }
  if (!v || v == 'null') {
    return '--';
  }
  if (info.dataType === 'datetime') {
    return Moment(v).format('YYYY-MM-DD HH:mm:ss');
  }
  if (info.dataType === 'date') {
    if (isNaN(<any>(new Date(v)))) {
      return Moment(parseInt(v)).format('YYYY-MM-DD');
    } else {
      return Moment(v).format('YYYY-MM-DD');
    }
  }
  return v;
};

/** 内部故意攻击概率的表格 */
const innerResultFields = ref([{
  field: 'level',
  label: '风险减缓控制水平'
}, {
  field: 'competencyLevel',
  label: '动机和能力'
}, {
  field: 'value',
  label: '重标识攻击概率',
  align: 'right'
}]);
const innerResultData = ref([{
  guid: '1',
  level: '高',
  competencyLevel: '低',
  value: '0.05'
}, {
  guid: '2',
  level: '高',
  competencyLevel: '中',
  tooltip: true,
  value: '0.1'
}, {
  guid: '3',
  level: '高',
  competencyLevel: '高',
  tooltip: true,
  value: '0.2'
}, {
  guid: '4',
  level: '中',
  competencyLevel: '低',
  value: '0.2'
}, {
  guid: '5',
  level: '中',
  competencyLevel: '中',
  value: '0.3'
}, {
  guid: '6',
  level: '中',
  competencyLevel: '高',
  value: '0.4'
}, {
  guid: '7',
  level: '低',
  competencyLevel: '低',
  value: '0.4'
}, {
  guid: '8',
  level: '低',
  competencyLevel: '中',
  value: '0.5'
}, {
  guid: '9',
  level: '低',
  competencyLevel: '高',
  value: '0.6'
}]);

const arrayInnerSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex > 0) {
    return [1, 1];
  }

  // 查找当前字段值相同的连续行
  let startRow = rowIndex;
  let endRow = rowIndex;
  let field = 'level';
  // 向前查找
  while (startRow > 0 && innerResultData.value[startRow - 1][field] === innerResultData.value[rowIndex][field]) {
    startRow--;
  }

  // 向后查找
  while (endRow < innerResultData.value.length - 1 && innerResultData.value[endRow + 1][field] === innerResultData.value[rowIndex][field]) {
    endRow++;
  }

  // 如果当前行不是相同值组的起始行,则不显示
  if (startRow !== rowIndex) {
    return [0, 0];
  }

  // 返回合并的行数
  const rowspan = endRow - startRow + 1;
  return [rowspan, 1];
}

const handleInnerCellClass = ({ row, column, rowIndex, columnIndex }) => {
  if (rowIndex == 0 && columnIndex > 0) {
    return 'cell-tooltip-bg';
  }
  return '';
}

/** 对抗性测试变量表格字段配置 */
const adversarialTestFields = ref([{
  field: 'index',
  label: '序号',
  align: 'center',
}, {
  field: 'chName',
  label: '数据项'
}, {
  field: 'uniqueScore',
  label: '唯一性分值',
  align: 'right'
}, {
  field: 'influenceScore',
  label: '影响力分值',
  align: 'right'
}, {
  field: 'dataAttrIdentScore',
  label: '数据属性标识度分值',
  align: 'right'
}]);

const pageChange = (info) => {
  emits('pageChange', info);
}

const downPromise: any = ref(null)
const downErrorFile = () => {
  if (downPromise.value) {
    return;
  }
  downDicomPath(props.analysisResultInfo.guid).then((res: any) => {
     downPromise.value = null
      if (res && !res.msg) {
        debugger
        download(res, (props.oldAnonTaskValueInfo.taskName) + '_需修正文件明细表.xlsx', 'excel')
      } else {
        res?.msg && ElMessage.error(res?.msg);
      }
  })
}

defineExpose({
  report,
})

</script>

<style lang="scss" scoped>
.analysis-result-main {
  min-height: 250px;
  width: 100%;

  .value-desc {
    font-size: 14px;
    color: #212121;
    line-height: 21px;
  }

  .result-title {
    font-size: 16px;
    color: #212121;
    line-height: 24px;
    font-weight: 600;
    margin-bottom: 6px;
  }

  .result-title-h1 {
    color: #212121;
    font-weight: 600;
    font-size: 24px;
    text-align: center;
    line-height: 36px;
    margin-top: 12px;
  }

  .result-title-desc {
    color: #666;
    font-size: 14px;
    line-height: 21px;
    margin-top: 12px;
  }

  .kpi-content {
    display: flex;
    flex-direction: row;
    column-gap: 12px;
    row-gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
  }

  .border-content {
    height: 76px;
    display: flex;
    flex-direction: column;
    align-items: left;
    padding-left: 16px;
    justify-content: center;
    border: 1px solid #d9d9d9;
    width: calc(20% - 8px);
    min-width: 228px;
    border-radius: 2px;
    padding-left: 16px;

    .number {
      font-weight: 700;
      font-size: 20px;
      color: #212121;
      line-height: 30px;
      margin-top: 2px;

      &.score-color {
        color: #FF5F1F;
      }
    }

    .text {
      font-size: 14px;
      line-height: 21px;
      color: #666666;
      display: flex;

      .el-icon {
        color: #b2b2b2;
      }
    }
  }

  .result-table-desc {
    font-size: 14px;
    color: #999999;
    line-height: 21px;
  }

  .row-two-main {
    margin-top: 18px;
    display: flex;

    .table-one {
      width: 586px;

      &.border {
        border: 1px solid #d9d9d9;
        padding: 14px 18px 18px;
      }
    }

    .table-two {
      margin-left: 20px;
      width: calc(100% - 606px);

      &.border {
        border: 1px solid #d9d9d9;
        padding: 14px 18px 18px;
      }
    }
  }
}

.empty-content {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 316px;
  width: 100%;
  flex-direction: column;

  .empty-text {
    font-size: 14px;
    color: #b2b2b2;
  }
}

.report-main.analysis-result-main {
  width: 625px;

  .kpi-content {
    margin-bottom: 0px;

    .border-content {
      width: calc(33% - 8px);
      min-width: 168px;
    }
  }
}

.reject {
      background-color: #FDF2F4;
      box-shadow: 0 0 0 1px #E63E33;
      margin-bottom: 8px;

      .header_title {
          .el-icon {
            color: #E63E33;
          }
        }
    }

.header_title {
  height: 40px;
  padding: 0 16px;
  display: flex;
  align-items: center;

  .title_text {
    line-height: 22px;
    font-size: 14px;
    color: var(--el-color-regular);
    font-weight: 600;
    display: flex;
    align-items: center;

    .title_icon {
      width: 26px;
      height: 21px;
      margin-right: 4px;
      cursor: pointer;

      &.active {
        transform: rotate(90deg);
      }
    }

    &.link {
      cursor: pointer;
      color: var(--el-color-primary);
    }
  }
}

p {
  font-family: simsun;
  font-size: 14px;
  line-height: 21px;
  color: #212121;
}

h1 {
  font-family: simsun;
  font-size: 18px;
  font-weight: 700;
  color: #212121;
  text-align: left; margin-top: 10px; margin-bottom: 10px;
}
</style>