     1|                                                                                view_definition
     2|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     3|  WITH RECURSIVE base AS (                                                                                +
     4|          SELECT zq_zfba_wcnr_xyr.ajxx_ajbhs,                                                                                +
     5|             zq_zfba_wcnr_xyr.xyrxx_sfzh,                                                                                +
     6|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ajbh,                                                                                +
     7|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ajlx,                                                                                +
     8|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ajlx_dm,                                                                                +
     9|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ajmc,                                                                                +
    10|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ay,                                                                                +
    11|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_ay_dm,                                                                                +
    12|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_cbdw_bh,                                                                                +
    13|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
    14|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_cbqy_bh,                                                                                +
    15|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_cbqy_bh_dm,                                                                                +
    16|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_cbqy_jc,                                                                                +
    17|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_isdel,                                                                                +
    18|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_isdel_dm,                                                                                +
    19|             zq_zfba_wcnr_xyr.ajxx_join_ajxx_lasj,                                                                                +
    20|             zq_zfba_wcnr_xyr.xyrxx_ay_bh,                                                                                +
    21|             zq_zfba_wcnr_xyr.xyrxx_ay_bh_dm,                                                                                +
    22|             zq_zfba_wcnr_xyr.xyrxx_ay_mc,                                                                                +
    23|             zq_zfba_wcnr_xyr.xyrxx_bh,                                                                                +
    24|             zq_zfba_wcnr_xyr.xyrxx_bz,                                                                                +
    25|             zq_zfba_wcnr_xyr.xyrxx_bzdzk,                                                                                +
    26|             zq_zfba_wcnr_xyr.xyrxx_c_cssj,                                                                                +
    27|             zq_zfba_wcnr_xyr.xyrxx_cbdw_bh,                                                                                +
    28|             zq_zfba_wcnr_xyr.xyrxx_cbdw_bh_dm,                                                                                +
    29|             zq_zfba_wcnr_xyr.xyrxx_cbqy_bh,                                                                                +
    30|             zq_zfba_wcnr_xyr.xyrxx_cbqy_bh_dm,                                                                                +
    31|             zq_zfba_wcnr_xyr.xyrxx_ch,                                                                                +
    32|             zq_zfba_wcnr_xyr.xyrxx_crj_zjhm,                                                                                +
    33|             zq_zfba_wcnr_xyr.xyrxx_crj_zjlx,                                                                                +
    34|             zq_zfba_wcnr_xyr.xyrxx_crj_zjlx_dm,                                                                                +
    35|             zq_zfba_wcnr_xyr.xyrxx_cskssj,                                                                                +
    36|             zq_zfba_wcnr_xyr.xyrxx_csrq,                                                                                +
    37|             zq_zfba_wcnr_xyr.xyrxx_cym,                                                                                +
    38|             zq_zfba_wcnr_xyr.xyrxx_dataversion,                                                                                +
    39|             zq_zfba_wcnr_xyr.xyrxx_dlr,                                                                                +
    40|             zq_zfba_wcnr_xyr.xyrxx_dlrdh,                                                                                +
    41|             zq_zfba_wcnr_xyr.xyrxx_dna,                                                                                +
    42|             zq_zfba_wcnr_xyr.xyrxx_dwry,                                                                                +
    43|             zq_zfba_wcnr_xyr.xyrxx_fzjl,                                                                                +
    44|             zq_zfba_wcnr_xyr.xyrxx_gasj,                                                                                +
    45|             zq_zfba_wcnr_xyr.xyrxx_gatsf,                                                                                +
    46|             zq_zfba_wcnr_xyr.xyrxx_gatsf_dm,                                                                                +
    47|             zq_zfba_wcnr_xyr.xyrxx_gcbh,                                                                                +
    48|             zq_zfba_wcnr_xyr.xyrxx_gj,                                                                                +
    49|             zq_zfba_wcnr_xyr.xyrxx_gj_dm,                                                                                +
    50|             zq_zfba_wcnr_xyr.xyrxx_gjgzry,                                                                                +
    51|             zq_zfba_wcnr_xyr.xyrxx_gjgzry_dm,                                                                                +
    52|             zq_zfba_wcnr_xyr.xyrxx_grxg,                                                                                +
    53|             zq_zfba_wcnr_xyr.xyrxx_gzdw,                                                                                +
    54|             zq_zfba_wcnr_xyr.xyrxx_gzry,                                                                                +
    55|             zq_zfba_wcnr_xyr.xyrxx_gzry_dm,                                                                                +
    56|             zq_zfba_wcnr_xyr.xyrxx_hjd,                                                                                +
    57|             zq_zfba_wcnr_xyr.xyrxx_hjdxz,                                                                                +
    58|             zq_zfba_wcnr_xyr.xyrxx_hjdxz_x,                                                                                +
    59|             zq_zfba_wcnr_xyr.xyrxx_hjdxz_y,                                                                                +
    60|             zq_zfba_wcnr_xyr.xyrxx_hjdxzqh,                                                                                +
    61|             zq_zfba_wcnr_xyr.xyrxx_hjdxzqh_dm,                                                                                +
    62|             zq_zfba_wcnr_xyr.xyrxx_hyzk,                                                                                +
    63|             zq_zfba_wcnr_xyr.xyrxx_hyzk_dm,                                                                                +
    64|             zq_zfba_wcnr_xyr.xyrxx_id,                                                                                +
    65|             zq_zfba_wcnr_xyr.xyrxx_isdel,                                                                                +
    66|             zq_zfba_wcnr_xyr.xyrxx_isdel_dm,                                                                                +
    67|             zq_zfba_wcnr_xyr.xyrxx_isfc,                                                                                +
    68|             zq_zfba_wcnr_xyr.xyrxx_isfc_dm,                                                                                +
    69|             zq_zfba_wcnr_xyr.xyrxx_isgzry,                                                                                +
    70|             zq_zfba_wcnr_xyr.xyrxx_isgzry_dm,                                                                                +
    71|             zq_zfba_wcnr_xyr.xyrxx_isxg,                                                                                +
    72|             zq_zfba_wcnr_xyr.xyrxx_isxg_dm,                                                                                +
    73|             zq_zfba_wcnr_xyr.xyrxx_jg,                                                                                +
    74|             zq_zfba_wcnr_xyr.xyrxx_jg_dm,                                                                                +
    75|             zq_zfba_wcnr_xyr.xyrxx_jtzk,                                                                                +
    76|             zq_zfba_wcnr_xyr.xyrxx_jzdxzqh,                                                                                +
    77|             zq_zfba_wcnr_xyr.xyrxx_jzdxzqh_dm,                                                                                +
    78|             zq_zfba_wcnr_xyr.xyrxx_jzdz,                                                                                +
    79|             zq_zfba_wcnr_xyr.xyrxx_ky,                                                                                +
    80|             zq_zfba_wcnr_xyr.xyrxx_lrr_sfzh,                                                                                +
    81|             zq_zfba_wcnr_xyr.xyrxx_lrsj,                                                                                +
    82|             zq_zfba_wcnr_xyr.xyrxx_lxfs,                                                                                +
    83|             zq_zfba_wcnr_xyr.xyrxx_mgry,                                                                                +
    84|             zq_zfba_wcnr_xyr.xyrxx_mgry_dm,                                                                                +
    85|             zq_zfba_wcnr_xyr.xyrxx_mgrylx,                                                                                +
    86|             zq_zfba_wcnr_xyr.xyrxx_mgrylx_dm,                                                                                +
    87|             zq_zfba_wcnr_xyr.xyrxx_mz,                                                                                +
    88|             zq_zfba_wcnr_xyr.xyrxx_mz_dm,                                                                                +
    89|             zq_zfba_wcnr_xyr.xyrxx_nl,                                                                                +
    90|             zq_zfba_wcnr_xyr.xyrxx_nlsx,                                                                                +
    91|             zq_zfba_wcnr_xyr.xyrxx_qkqk,                                                                                +
    92|             zq_zfba_wcnr_xyr.xyrxx_qq,                                                                                +
    93|             zq_zfba_wcnr_xyr.xyrxx_qtlxfs,                                                                                +
    94|             zq_zfba_wcnr_xyr.xyrxx_qtzjhm1,                                                                                +
    95|             zq_zfba_wcnr_xyr.xyrxx_qtzjhm2,                                                                                +
    96|             zq_zfba_wcnr_xyr.xyrxx_qtzjhm3,                                                                                +
    97|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx1,                                                                                +
    98|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx1_dm,                                                                                +
    99|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx2,                                                                                +
   100|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx2_dm,                                                                                +
   101|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx3,                                                                                +
   102|             zq_zfba_wcnr_xyr.xyrxx_qtzjlx3_dm,                                                                                +
   103|             zq_zfba_wcnr_xyr.xyrxx_qzcs,                                                                                +
   104|             zq_zfba_wcnr_xyr.xyrxx_qzcsjssj,                                                                                +
   105|             zq_zfba_wcnr_xyr.xyrxx_qzcskssj,                                                                                +
   106|             zq_zfba_wcnr_xyr.xyrxx_r_rssj,                                                                                +
   107|             zq_zfba_wcnr_xyr.xyrxx_rddb,                                                                                +
   108|             zq_zfba_wcnr_xyr.xyrxx_rddb_dm,                                                                                +
   109|             zq_zfba_wcnr_xyr.xyrxx_rdjb,                                                                                +
   110|             zq_zfba_wcnr_xyr.xyrxx_rdjb_dm,                                                                                +
   111|             zq_zfba_wcnr_xyr.xyrxx_rdsj,                                                                                +
   112|             zq_zfba_wcnr_xyr.xyrxx_rybh,                                                                                +
   113|             zq_zfba_wcnr_xyr.xyrxx_ryzt,                                                                                +
   114|             zq_zfba_wcnr_xyr.xyrxx_ryzt_dm,                                                                                +
   115|             zq_zfba_wcnr_xyr.xyrxx_scspzt,                                                                                +
   116|             zq_zfba_wcnr_xyr.xyrxx_scspzt_dm,                                                                                +
   117|             zq_zfba_wcnr_xyr.xyrxx_sf,                                                                                +
   118|             zq_zfba_wcnr_xyr.xyrxx_sf_dm,                                                                                +
   119|             zq_zfba_wcnr_xyr.xyrxx_sfbk,                                                                                +
   120|             zq_zfba_wcnr_xyr.xyrxx_sfbk_dm,                                                                                +
   121|             zq_zfba_wcnr_xyr.xyrxx_sfbmsf,                                                                                +
   122|             zq_zfba_wcnr_xyr.xyrxx_sfbmsf_dm,                                                                                +
   123|             zq_zfba_wcnr_xyr.xyrxx_sfda,                                                                                +
   124|             zq_zfba_wcnr_xyr.xyrxx_sfda_dm,                                                                                +
   125|             zq_zfba_wcnr_xyr.xyrxx_sfdy,                                                                                +
   126|             zq_zfba_wcnr_xyr.xyrxx_sfdy_dm,                                                                                +
   127|             zq_zfba_wcnr_xyr.xyrxx_sfga,                                                                                +
   128|             zq_zfba_wcnr_xyr.xyrxx_sfga_dm,                                                                                +
   129|             zq_zfba_wcnr_xyr.xyrxx_sfgatjm,                                                                                +
   130|             zq_zfba_wcnr_xyr.xyrxx_sfgatjm_dm,                                                                                +
   131|             zq_zfba_wcnr_xyr.xyrxx_sflar,                                                                                +
   132|             zq_zfba_wcnr_xyr.xyrxx_sflar_dm,                                                                                +
   133|             zq_zfba_wcnr_xyr.xyrxx_sftb,                                                                                +
   134|             zq_zfba_wcnr_xyr.xyrxx_sftb_dm,                                                                                +
   135|             zq_zfba_wcnr_xyr.xyrxx_sftsqt,                                                                                +
   136|             zq_zfba_wcnr_xyr.xyrxx_sftsqt_dm,                                                                                +
   137|             zq_zfba_wcnr_xyr.xyrxx_sfxd,                                                                                +
   138|             zq_zfba_wcnr_xyr.xyrxx_sfxd_dm,                                                                                +
   139|             zq_zfba_wcnr_xyr.xyrxx_sfythcj,                                                                                +
   140|             zq_zfba_wcnr_xyr.xyrxx_sfythcj_dm,                                                                                +
   141|             zq_zfba_wcnr_xyr.xyrxx_sfzbm,                                                                                +
   142|             zq_zfba_wcnr_xyr.xyrxx_sfzbm_dm,                                                                                +
   143|             zq_zfba_wcnr_xyr.xyrxx_sg,                                                                                +
   144|             zq_zfba_wcnr_xyr.xyrxx_shgx,                                                                                +
   145|             zq_zfba_wcnr_xyr.xyrxx_szdzb,                                                                                +
   146|             zq_zfba_wcnr_xyr.xyrxx_szssrd,                                                                                +
   147|             zq_zfba_wcnr_xyr.xyrxx_szsszx,                                                                                +
   148|             zq_zfba_wcnr_xyr.xyrxx_tbbj,                                                                                +
   149|             zq_zfba_wcnr_xyr.xyrxx_tbsj,                                                                                +
   150|             zq_zfba_wcnr_xyr.xyrxx_tmtz,                                                                                +
   151|             zq_zfba_wcnr_xyr.xyrxx_tsqt,                                                                                +
   152|             zq_zfba_wcnr_xyr.xyrxx_tsqt_dm,                                                                                +
   153|             zq_zfba_wcnr_xyr.xyrxx_tx,                                                                                +
   154|             zq_zfba_wcnr_xyr.xyrxx_tx_dm,                                                                                +
   155|             zq_zfba_wcnr_xyr.xyrxx_wfss,                                                                                +
   156|             zq_zfba_wcnr_xyr.xyrxx_whcd,                                                                                +
   157|             zq_zfba_wcnr_xyr.xyrxx_whcd_dm,                                                                                +
   158|             zq_zfba_wcnr_xyr.xyrxx_wx,                                                                                +
   159|             zq_zfba_wcnr_xyr.xyrxx_xb,                                                                                +
   160|             zq_zfba_wcnr_xyr.xyrxx_xb_dm,                                                                                +
   161|             zq_zfba_wcnr_xyr.xyrxx_xdjyjg,                                                                                +
   162|             zq_zfba_wcnr_xyr.xyrxx_xdjyjg_dm,                                                                                +
   163|             zq_zfba_wcnr_xyr.xyrxx_xgr_sfzh,                                                                                +
   164|             zq_zfba_wcnr_xyr.xyrxx_xgsj,                                                                                +
   165|             zq_zfba_wcnr_xyr.xyrxx_xm,                                                                                +
   166|             zq_zfba_wcnr_xyr.xyrxx_xx,                                                                                +
   167|             zq_zfba_wcnr_xyr.xyrxx_xx_dm,                                                                                +
   168|             zq_zfba_wcnr_xyr.xyrxx_xyr_nl,                                                                                +
   169|             zq_zfba_wcnr_xyr.xyrxx_xzd,                                                                                +
   170|             zq_zfba_wcnr_xyr.xyrxx_xzdxz,                                                                                +
   171|             zq_zfba_wcnr_xyr.xyrxx_xzdxz_x,                                                                                +
   172|             zq_zfba_wcnr_xyr.xyrxx_xzdxz_y,                                                                                +
   173|             zq_zfba_wcnr_xyr.xyrxx_xzq,                                                                                +
   174|             zq_zfba_wcnr_xyr.xyrxx_xzqdm,                                                                                +
   175|             zq_zfba_wcnr_xyr.xyrxx_ywjsxx,                                                                                +
   176|             zq_zfba_wcnr_xyr.xyrxx_ywjsxx_dm,                                                                                +
   177|             zq_zfba_wcnr_xyr.xyrxx_ywm,                                                                                +
   178|             zq_zfba_wcnr_xyr.xyrxx_ywx,                                                                                +
   179|             zq_zfba_wcnr_xyr.xyrxx_yxzh,                                                                                +
   180|             zq_zfba_wcnr_xyr.xyrxx_zagj,                                                                                +
   181|             zq_zfba_wcnr_xyr.xyrxx_zagj_dm,                                                                                +
   182|             zq_zfba_wcnr_xyr.xyrxx_zatd,                                                                                +
   183|             zq_zfba_wcnr_xyr.xyrxx_zatd_dm,                                                                                +
   184|             zq_zfba_wcnr_xyr.xyrxx_zc,                                                                                +
   185|             zq_zfba_wcnr_xyr.xyrxx_zfzh,                                                                                +
   186|             zq_zfba_wcnr_xyr.xyrxx_zhdd,                                                                                +
   187|             zq_zfba_wcnr_xyr.xyrxx_zhjg,                                                                                +
   188|             zq_zfba_wcnr_xyr.xyrxx_zhr,                                                                                +
   189|             zq_zfba_wcnr_xyr.xyrxx_zhsj,                                                                                +
   190|             zq_zfba_wcnr_xyr.xyrxx_zhxzb,                                                                                +
   191|             zq_zfba_wcnr_xyr.xyrxx_zhyzb,                                                                                +
   192|             zq_zfba_wcnr_xyr.xyrxx_zm,                                                                                +
   193|             zq_zfba_wcnr_xyr.xyrxx_zmbh,                                                                                +
   194|             zq_zfba_wcnr_xyr.xyrxx_zmbh_dm,                                                                                +
   195|             zq_zfba_wcnr_xyr.xyrxx_zpid,                                                                                +
   196|             zq_zfba_wcnr_xyr.xyrxx_zszt,                                                                                +
   197|             zq_zfba_wcnr_xyr.xyrxx_zw,                                                                                +
   198|             zq_zfba_wcnr_xyr.xyrxx_zwxx,                                                                                +
   199|             zq_zfba_wcnr_xyr.xyrxx_zxjb,                                                                                +
   200|             zq_zfba_wcnr_xyr.xyrxx_zxjb_dm,                                                                                +
   201|             zq_zfba_wcnr_xyr.xyrxx_zxwy,                                                                                +
   202|             zq_zfba_wcnr_xyr.xyrxx_zxwy_dm,                                                                                +
   203|             zq_zfba_wcnr_xyr.xyrxx_zy,                                                                                +
   204|             zq_zfba_wcnr_xyr.xyrxx_zy_dm,                                                                                +
   205|             zq_zfba_wcnr_xyr.xyrxx_zylb,                                                                                +
   206|             zq_zfba_wcnr_xyr.xyrxx_zzmm,                                                                                +
   207|             zq_zfba_wcnr_xyr.xyrxx_zzmm_dm                                                                                +
   208|            FROM ywdata.zq_zfba_wcnr_xyr                                                                                +
   209|           WHERE (((zq_zfba_wcnr_xyr.ajxx_join_ajxx_isdel_dm)::integer = 0) AND ((zq_zfba_wcnr_xyr.xyrxx_isdel_dm)::integer = 0) AND ((zq_zfba_wcnr_xyr.xyrxx_sfda_dm)::integer = 1))+
   210|         ), xz_cfjds AS (                                                                                +
   211|          SELECT zq_zfba_xzcfjds.ajxx_ajbh,                                                                                +
   212|             zq_zfba_xzcfjds.xzcfjds_rybh AS rybh                                                                                +
   213|            FROM ywdata.zq_zfba_xzcfjds                                                                                +
   214|         UNION                                                                                +
   215|          SELECT zq_zfba_byxzcfjds.ajxx_ajbh,                                                                                +
   216|             zq_zfba_byxzcfjds.byxzcfjds_rybh AS rybh                                                                                +
   217|            FROM ywdata.zq_zfba_byxzcfjds                                                                                +
   218|         )                                                                                +
   219|  SELECT DISTINCT b.ajxx_join_ajxx_ajbh AS "案件编号",                                                                                +
   220|     b.ajxx_join_ajxx_ajlx AS "案件类型",                                                                                +
   221|     b.ajxx_join_ajxx_ay AS "案由",                                                                                +
   222|     b.ajxx_join_ajxx_ay_dm AS "案由代码",                                                                                +
   223|     "left"(b.ajxx_join_ajxx_cbqy_bh_dm, 6) AS "地区",                                                                                +
   224|     b.ajxx_join_ajxx_cbdw_bh AS "办案单位",                                                                                +
   225|     b.ajxx_join_ajxx_lasj AS "立案时间",                                                                                +
   226|     b.xyrxx_xm AS "姓名",                                                                                +
   227|     b.xyrxx_sfzh AS "身份证号",                                                                                +
   228|     b.xyrxx_rybh AS "人员编号",                                                                                +
   229|     b.xyrxx_hjdxz AS "户籍地",                                                                                +
   230|     b.xyrxx_nl AS "年龄",                                                                                +
   231|     b.xyrxx_isdel AS "是否删除",                                                                                +
   232|     b.xyrxx_jzdxzqh AS "居住地",                                                                                +
   233|     b.xyrxx_lrsj AS "录入时间",                                                                                +
   234|     xj.xxmc AS "学校名称",                                                                                +
   235|     xj.njmc AS "年级",                                                                                +
   236|     xj.bjmc AS "班级",                                                                                +
   237|     xj.jdzt AS "就读状态"                                                                                +
   238|    FROM ((base b                                                                                +
   239|      LEFT JOIN xz_cfjds xzm ON (((b.ajxx_join_ajxx_ajlx = '行政'::text) AND (xzm.ajxx_ajbh = b.ajxx_join_ajxx_ajbh) AND (xzm.rybh = b.xyrxx_rybh))))                                +
   240|      LEFT JOIN ywdata.sh_gd_zxxxsxj_xx xj ON (((xj.sfzjh)::text = b.xyrxx_sfzh)))                                                                                +
   241|   WHERE ((b.ajxx_join_ajxx_ajlx = '刑事'::text) OR ((b.ajxx_join_ajxx_ajlx = '行政'::text) AND (xzm.ajxx_ajbh IS NOT NULL)));
   242|(1 row)
   243|
   244|


找到了，是 `v_wcnr_wfry_base`，来自 `ywdata.zq_zfba_wcnr_xyr` 表。让我看看其他几个相关视图。

Explanation:
Now I have the full view definition for `v_wcnr_wfry_base`. Let me understand the logic:

**Table source**: `ywdata.zq_zfba_wcnr_xyr` (not `zq_zfba_xyrxx` that we used before)

**Filters on base CTE**:
- `ajxx_join_ajxx_isdel_dm = 0` (case not deleted)
- `xyrxx_isdel_dm = 0` (person not deleted)
- `xyrxx_sfda_dm = 1` (身份状态? 身份档案? = 1)

**CTEs**:
- `base` - main person+case data from `zq_zfba_wcnr_xyr`
- `xz_cfjds` - UNION of administrative penalty decision books + non-administrative penalty decision books (ajbh + rybh)

**Final WHERE**:
- Criminal cases: `ajlx = '刑事'` (all criminal cases)
- Administrative cases: `ajlx = '行政'` AND exists in `xz_cfjds` (has penalty decision)

**Output fields**:
- 案件编号, 案件类型, 案由, 案由代码
- 地区 (left(cbqy_bh_dm, 6))
- 办案单位 (cbdw_bh)
- 立案时间
- 姓名, 身份证号, 人员编号
- 户籍地, 年龄 (xyrxx_nl), 居住地, 录入时间
- 学校名称, 年级, 班级, 就读状态 (from school table)

**Key differences from our v_wcnr_minor_detail**:
1. Uses `zq_zfba_wcnr_xyr` table (not `zq_zfba_xyrxx`)
2. Has deletion filters (`isdel_dm = 0`)
3. Has `sfda_dm = 1` filter
4. Joins with school info (`sh_gd_zxxxsxj_xx`)
5. Uses `xyrxx_nl` (existing age field) not calculated age
6. Filters: criminal cases all included, admin cases only if they have penalty decisions
7. Uses `xz_cfjds` CTE for admin case filtering

Now let me get the other views too to give a complete picture.


     1|                                                                                view_definition
     2|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     3|  WITH RECURSIVE wf_validated AS MATERIALIZED (                                                                                +
     4|          SELECT zq_zfba_xyrxx.xyrxx_sfzh,                                                                                +
     5|             zq_zfba_xyrxx.xyrxx_xm,                                                                                +
     6|             zq_zfba_xyrxx.xyrxx_xb,                                                                                +
     7|             zq_zfba_xyrxx.xyrxx_lrsj,                                                                                +
     8|             zq_zfba_xyrxx.ajxx_join_ajxx_ajbh,                                                                                +
     9|             zq_zfba_xyrxx.ajxx_join_ajxx_lasj,                                                                                +
    10|             zq_zfba_xyrxx.ajxx_join_ajxx_ajlx,                                                                                +
    11|             zq_zfba_xyrxx.ajxx_join_ajxx_ay,                                                                                +
    12|             zq_zfba_xyrxx.xyrxx_hjdxzqh,                                                                                +
    13|             zq_zfba_xyrxx.xyrxx_hjdxzqh_dm,                                                                                +
    14|             zq_zfba_xyrxx.xyrxx_hjdxz,                                                                                +
    15|             zq_zfba_xyrxx.xyrxx_xzdxz,                                                                                +
    16|             zq_zfba_xyrxx.ajxx_join_ajxx_cbdw_bh,                                                                                +
    17|             zq_zfba_xyrxx.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
    18|             zq_zfba_xyrxx.xyrxx_rybh,                                                                                +
    19|             to_date("substring"(zq_zfba_xyrxx.xyrxx_sfzh, 7, 8), 'YYYYMMDD'::text) AS birthday                                                                                +
    20|            FROM ywdata.zq_zfba_xyrxx                                                                                +
    21|           WHERE ((zq_zfba_xyrxx.ajxx_join_ajxx_isdel_dm = '0'::text) AND (zq_zfba_xyrxx.xyrxx_sfzh IS NOT NULL) AND (length(zq_zfba_xyrxx.xyrxx_sfzh) = 18) AND (zq_zfba_xyrxx.xyrxx_sfzh ~ '^\d{17}[\dXx]$'::text) AND ("substring"(zq_zfba_xyrxx.xyrxx_sfzh, 7, 8) ~ '^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$'::text) AND ("substring"(zq_zfba_xyrxx.xyrxx_sfzh, 7, 8) >= to_char((CURRENT_DATE - '20 years'::pg_catalog.interval), 'YYYYMMDD'::text)))+
    22|         ), xz_keys AS MATERIALIZED (                                                                                +
    23|          SELECT DISTINCT zq_zfba_byxzcfjds.ajxx_ajbh AS ajbh,                                                                                +
    24|             zq_zfba_byxzcfjds.byxzcfjds_rybh AS rybh                                                                                +
    25|            FROM ywdata.zq_zfba_byxzcfjds                                                                                +
    26|           WHERE (zq_zfba_byxzcfjds.byxzcfjds_cbryj !~ '违法事实不能成立'::text)                                                                                +
    27|         UNION                                                                                +
    28|          SELECT DISTINCT zq_zfba_xzcfjds.ajxx_ajbh AS ajbh,                                                                                +
    29|             zq_zfba_xzcfjds.xzcfjds_rybh AS rybh                                                                                +
    30|            FROM ywdata.zq_zfba_xzcfjds                                                                                +
    31|         ), wf_xz_filtered AS MATERIALIZED (                                                                                +
    32|          SELECT v.xyrxx_sfzh,                                                                                +
    33|             v.xyrxx_xm,                                                                                +
    34|             v.xyrxx_xb,                                                                                +
    35|             v.xyrxx_lrsj,                                                                                +
    36|             v.ajxx_join_ajxx_ajbh,                                                                                +
    37|             v.ajxx_join_ajxx_lasj,                                                                                +
    38|             v.ajxx_join_ajxx_ajlx,                                                                                +
    39|             v.ajxx_join_ajxx_ay,                                                                                +
    40|             v.xyrxx_hjdxzqh,                                                                                +
    41|             v.xyrxx_hjdxzqh_dm,                                                                                +
    42|             v.xyrxx_hjdxz,                                                                                +
    43|             v.xyrxx_xzdxz,                                                                                +
    44|             v.ajxx_join_ajxx_cbdw_bh,                                                                                +
    45|             v.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
    46|             v.xyrxx_rybh,                                                                                +
    47|             v.birthday                                                                                +
    48|            FROM wf_validated v                                                                                +
    49|           WHERE ((v.ajxx_join_ajxx_ajlx = '刑事'::text) AND (NOT (EXISTS ( SELECT 1                                                                                +
    50|                    FROM ywdata.zq_zfba_byxzcfjds bxf                                                                                +
    51|                   WHERE ((bxf.ajxx_ajbh = v.ajxx_join_ajxx_ajbh) AND (bxf.byxzcfjds_rybh = v.xyrxx_rybh) AND (bxf.byxzcfjds_cbryj ~ '违法事实不能成立'::text))))) AND (NOT (EXISTS ( SELECT 1                                                                                +
    52|                    FROM ywdata.zq_zfba_wenshu ws                                                                                +
    53|                   WHERE ((ws.ajbh = v.ajxx_join_ajxx_ajbh) AND (ws.xgry_xm = v.xyrxx_xm) AND (ws.wsmc ~ '终止侦查决定书'::text))))))                                                                                +
    54|         UNION ALL                                                                                +
    55|          SELECT v.xyrxx_sfzh,                                                                                +
    56|             v.xyrxx_xm,                                                                                +
    57|             v.xyrxx_xb,                                                                                +
    58|             v.xyrxx_lrsj,                                                                                +
    59|             v.ajxx_join_ajxx_ajbh,                                                                                +
    60|             v.ajxx_join_ajxx_lasj,                                                                                +
    61|             v.ajxx_join_ajxx_ajlx,                                                                                +
    62|             v.ajxx_join_ajxx_ay,                                                                                +
    63|             v.xyrxx_hjdxzqh,                                                                                +
    64|             v.xyrxx_hjdxzqh_dm,                                                                                +
    65|             v.xyrxx_hjdxz,                                                                                +
    66|             v.xyrxx_xzdxz,                                                                                +
    67|             v.ajxx_join_ajxx_cbdw_bh,                                                                                +
    68|             v.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
    69|             v.xyrxx_rybh,                                                                                +
    70|             v.birthday                                                                                +
    71|            FROM (wf_validated v                                                                                +
    72|              JOIN xz_keys k ON (((k.ajbh = v.ajxx_join_ajxx_ajbh) AND (k.rybh = v.xyrxx_rybh))))                                                                                +
    73|           WHERE (v.ajxx_join_ajxx_ajlx = '行政'::text)                                                                                +
    74|         ), wf_minor AS MATERIALIZED (                                                                                +
    75|          SELECT v.xyrxx_sfzh,                                                                                +
    76|             v.xyrxx_xm,                                                                                +
    77|             v.xyrxx_xb,                                                                                +
    78|             v.xyrxx_lrsj,                                                                                +
    79|             v.ajxx_join_ajxx_ajbh,                                                                                +
    80|             v.ajxx_join_ajxx_lasj,                                                                                +
    81|             v.ajxx_join_ajxx_ajlx,                                                                                +
    82|             v.ajxx_join_ajxx_ay,                                                                                +
    83|             v.xyrxx_hjdxzqh,                                                                                +
    84|             v.xyrxx_hjdxzqh_dm,                                                                                +
    85|             v.xyrxx_hjdxz,                                                                                +
    86|             v.xyrxx_xzdxz,                                                                                +
    87|             v.ajxx_join_ajxx_cbdw_bh,                                                                                +
    88|             v.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
    89|             v.xyrxx_rybh,                                                                                +
    90|             v.birthday,                                                                                +
    91|             aj.ajxx_fasj,                                                                                +
    92|             ("date_part"('year'::text, age(((aj.ajxx_fasj)::date)::timestamp without time zone, (v.birthday)::timestamp without time zone)))::integer AS fasj_age                                                                                +
    93|            FROM (wf_xz_filtered v                                                                                +
    94|              JOIN ywdata.zq_zfba_ajxx aj ON ((v.ajxx_join_ajxx_ajbh = aj.ajxx_ajbh)))                                                                                +
    95|           WHERE (("date_part"('year'::text, age(v.xyrxx_lrsj, (v.birthday)::timestamp without time zone)) < (18)::double precision) AND (v.ajxx_join_ajxx_ajbh <> ALL (ARRAY['A4453021205002025126001'::text, 'A4453816302002026026010'::text])) AND (v.xyrxx_rybh <> ALL (ARRAY['R4453021205002026023007'::text, 'R4453816302002026023012'::text])) AND (v.xyrxx_sfzh <> '445381200802232178'::text))                                                       +
    96|         ), combined AS MATERIALIZED (                                                                                +
    97|          SELECT ranked.xyrxx_sfzh,                                                                                +
    98|             min(ranked.xyrxx_xm) FILTER (WHERE (ranked.rn_desc = 1)) AS xyrxx_xm,                                                                                +
    99|             min(ranked.xyrxx_xb) FILTER (WHERE (ranked.rn_desc = 1)) AS xyrxx_xb,                                                                                +
   100|             min((ranked.birthday)::timestamp without time zone) FILTER (WHERE (ranked.rn_desc = 1)) AS birthday,                                                                                +
   101|             min(ranked.xyrxx_lrsj) FILTER (WHERE (ranked.rn_desc = 1)) AS xyrxx_lrsj,                                                                                +
   102|             min(ranked.fasj_age) FILTER (WHERE (ranked.rn_desc = 1)) AS "最近一次发案年龄",                                                                                +
   103|             string_agg(ranked.ajxx_join_ajxx_ajlx, ' → '::text ORDER BY ranked.ajxx_join_ajxx_lasj DESC NULLS LAST) AS "案件类型",                                                                                +
   104|             string_agg(to_char(ranked.ajxx_join_ajxx_lasj, 'YYYY-MM-DD'::text), ' → '::text ORDER BY ranked.ajxx_join_ajxx_lasj DESC NULLS LAST) AS "立案时间链",                                                                                +
   105|             string_agg(ranked.ajxx_join_ajxx_ajbh, ' → '::text ORDER BY ranked.ajxx_join_ajxx_lasj DESC NULLS LAST) AS "案件编号",                                                                                +
   106|             string_agg(ranked.ajxx_join_ajxx_ay, ' → '::text ORDER BY ranked.ajxx_join_ajxx_lasj DESC NULLS LAST) AS "案由",                                                                                +
   107|             string_agg(DISTINCT ranked.xyrxx_hjdxzqh, '、'::text) AS "户籍行政区",                                                                                +
   108|             string_agg(DISTINCT ranked.xyrxx_hjdxzqh_dm, '、'::text) AS "户籍地代码",                                                                                +
   109|             string_agg(DISTINCT ranked.xyrxx_hjdxz, '、'::text) AS "户籍地",                                                                                +
   110|             string_agg(DISTINCT ranked.xyrxx_xzdxz, '、'::text) AS "现住地",                                                                                +
   111|             string_agg(DISTINCT ranked.ajxx_join_ajxx_cbdw_bh, ' → '::text) AS "办案部门",                                                                                +
   112|             string_agg(DISTINCT ranked.ajxx_join_ajxx_cbdw_bh_dm, ' → '::text) AS "办案部门编码",                                                                                +
   113|             string_agg(ranked.xyrxx_rybh, ' → '::text ORDER BY ranked.ajxx_join_ajxx_lasj DESC NULLS LAST) AS "人员编号",                                                                                +
   114|             count(*) AS "违法次数"                                                                                +
   115|            FROM ( SELECT wf_minor.xyrxx_sfzh,                                                                                +
   116|                     wf_minor.xyrxx_xm,                                                                                +
   117|                     wf_minor.xyrxx_xb,                                                                                +
   118|                     wf_minor.xyrxx_lrsj,                                                                                +
   119|                     wf_minor.ajxx_join_ajxx_ajbh,                                                                                +
   120|                     wf_minor.ajxx_join_ajxx_lasj,                                                                                +
   121|

Use offset=121 to continue reading (showing 1-120 of 174 lines)


Explanation: The user wants to see the logic of `v_wcnr_wfry_jbxx` view. I've found it - it's from `ywdata.zq_zfba_wcnr_xyr` table (not `zq_zfba_xyrxx`). Let me read the complete definition of this view and the `v_wcnr_wfry_jbxx_base` view. Let me continue reading.


   121|                     wf_minor.ajxx_join_ajxx_ajlx,                                                                                +
   122|                     wf_minor.ajxx_join_ajxx_ay,                                                                                +
   123|                     wf_minor.xyrxx_hjdxzqh,                                                                                +
   124|                     wf_minor.xyrxx_hjdxzqh_dm,                                                                                +
   125|                     wf_minor.xyrxx_hjdxz,                                                                                +
   126|                     wf_minor.xyrxx_xzdxz,                                                                                +
   127|                     wf_minor.ajxx_join_ajxx_cbdw_bh,                                                                                +
   128|                     wf_minor.ajxx_join_ajxx_cbdw_bh_dm,                                                                                +
   129|                     wf_minor.xyrxx_rybh,                                                                                +
   130|                     wf_minor.birthday,                                                                                +
   131|                     wf_minor.ajxx_fasj,                                                                                +
   132|                     wf_minor.fasj_age,                                                                                +
   133|                     row_number() OVER (PARTITION BY wf_minor.xyrxx_sfzh ORDER BY wf_minor.ajxx_join_ajxx_lasj DESC NULLS LAST) AS rn_desc                                                                                +
   134|                    FROM wf_minor) ranked                                                                                +
   135|           GROUP BY ranked.xyrxx_sfzh                                                                                +
   136|         )                                                                                +
   137|  SELECT c.xyrxx_xm AS "姓名",                                                                                +
   138|     c.xyrxx_sfzh AS "身份证号",                                                                                +
   139|     c.xyrxx_xb AS "性别",                                                                                +
   140|     c."最近一次发案年龄",                                                                                +
   141|     ("date_part"('year'::text, age((CURRENT_DATE)::timestamp without time zone, c.birthday)))::integer AS "现在年龄",                                                                                +
   142|     c.xyrxx_lrsj AS "录入时间",                                                                                +
   143|     c."违法次数",                                                                                +
   144|     c."案件类型",                                                                                +
   145|     c."立案时间链",                                                                                +
   146|     c."案件编号",                                                                                +
   147|     c."案由",                                                                                +
   148|     c."户籍行政区",                                                                                +
   149|     c."户籍地代码",                                                                                +
   150|     c."户籍地",                                                                                +
   151|     c."现住地",                                                                                +
   152|     c."办案部门",                                                                                +
   153|     c."办案部门编码",                                                                                +
   154|     c."人员编号",                                                                                +
   155|     xi.xxmc AS "学校名称",                                                                                +
   156|     xi.njmc AS "年级名称",                                                                                +
   157|     xi.bjmc AS "班级名称",                                                                                +
   158|     xi.jdzt AS "就读状态"                                                                                +
   159|    FROM (combined c                                                                                +
   160|      LEFT JOIN LATERAL ( SELECT sh_gd_zxxxsxj_xx.sfzjh,                                                                                +
   161|             sh_gd_zxxxsxj_xx.xxmc,                                                                                +
   162|             sh_gd_zxxxsxj_xx.njmc,                                                                                +
   163|             sh_gd_zxxxsxj_xx.bjmc,                                                                                +
   164|             sh_gd_zxxxsxj_xx.jdzt                                                                                +
   165|            FROM ywdata.sh_gd_zxxxsxj_xx                                                                                +
   166|           WHERE ((sh_gd_zxxxsxj_xx.sfzjh)::text = c.xyrxx_sfzh)                                                                                +
   167|           ORDER BY                                                                                +
   168|                 CASE                                                                                +
   169|                     WHEN ((sh_gd_zxxxsxj_xx.jdzt)::text = '在校'::text) THEN 0                                                                                +
   170|                     ELSE 1                                                                                +
   171|                 END, sh_gd_zxxxsxj_xx.jdzt                                                                                +
   172|          LIMIT 1) xi ON (true));
   173|(1 row)
   174|
   175|


找到了。你说的应该是 `v_wcnr_wfry_jbxx`（未成年人违法犯罪人员基本信息视图），它依赖 `v_wcnr_wfry_base`。下面是逻辑拆解：

## `v_wcnr_wfry_base`（基础版本）

**数据源**：`ywdata.zq_zfba_wcnr_xyr`（未成年嫌疑人专项表）

**过滤条件**：
- 案件未删除 (`ajxx_join_ajxx_isdel_dm = 0`)
- 人员未删除 (`xyrxx_isdel_dm = 0`)
- 身份代码为 1 (`xyrxx_sfda_dm = 1`) — 即"未成年人"标记

**案件筛选**：
- **刑事案件**：排除有"不予处罚+违法事实不能成立"的 + 排除有"终止侦查决定书"的
- **行政案件**：必须在处罚决定书或不予处罚决定书中有记录（即不是空挂案件）

**输出**：一案一行，字段包括案件编号、类型、案由、地区、办案单位、立案时间、姓名、身份证、人员编号、户籍地、年龄、居住地、录入时间、学校信息。

---

## `v_wcnr_wfry_jbxx`（增强版本，按人聚合）

在 base 之上做了以下增强：

| 特性 | 说明 |
|------|------|
| **身份证校验** | 18位 + 正则 `^\d{17}[\dXx]$` + 出生日期合法 + 20年内出生 |
| **录入年龄<18** | `age(lrsj, birthday) < 18` |
| **排除特定案件** | 排除了2个特定案件编号 |
| **排除特定人员** | 排除了2个特定人员编号 |
| **排除特定身份证** | 排除了 `445381200802232178` |
| **按人聚合** | 一人一行，案件类型/时间链/编号/案由 用 `→` 连接 |
| **最近一次发案年龄** | 从案件表取 `ajxx_fasj` 计算 |
| **现在年龄** | 用 `birthday` 计算 |
| **多值聚合** | 户籍行政区、户籍地代码、户籍地、现住地、办案部门 聚合为 `、` 分隔 |
| **学校信息** | 通过 `LATERAL JOIN` 关联 `sh_gd_zxxxsxj_xx` 取学校名称、年级、班级、就读状态（优先"在校"） |

---

## 与 `v_wcnr_minor_detail`（我创建的）的区别

| 对比项 | `v_wcnr_wfry_jbxx` | `v_wcnr_minor_detail`（我建的） |
|--------|---------------------|-------------------------------|
| 数据源 | `zq_zfba_wcnr_xyr`（未成年专项表） | `zq_zfba_xyrxx`（通用嫌疑人表） |
| 按人聚合 | ✅ 一人一行 | ❌ 一案一行 |
| 学校信息 | ✅ | ❌ |
| 简要案情/发案地点 | ❌ | ✅ |
| 承办区域代码 | ❌ | ✅ |
| 身份证校验 | ✅ 严格 | ✅ 基础（18位非空） |

需要我把这些逻辑整合到一起吗？

Explanation:
好的，现在我明白了。用户提到的 `v_wcnr_base_jbxx` 实际上对应的是 `v_wcnr_wfry_jbxx`，而 `v_wcnr_wfry_base` 是它的基础版本。`v_wcnr_wfry_jbxx` 是在 `v_wcnr_wfry_base` 的基础上做了额外的过滤和增强。

让我总结一下这两个视图的逻辑：

1. **v_wcnr_wfry_base** — 基础版本：
   - 从 `ywdata.zq_zfba_wcnr_xyr` 表取数据（而不是 `ywdata.zq_zfba_xyrxx`）
   - 过滤条件：案件未删除 + 人员未删除 + 身份代码为1（服刑人员？）
   - 刑事案件：排除有"不予处罚"且"违法事实不能成立"的 + 排除有"终止侦查决定书"的
   - 行政案件：必须有关联的处罚记录（在 xz_keys 中）
   - 结果：案件编号、案件类型、案由、地区、办案单位、立案时间、姓名、身份证号、人员编号、户籍地、年龄、居住地、录入时间、学校信息
   - 排序：一案一行，刑事+行政（有处罚的）

2. **v_wcnr_wfry_jbxx** — 增强版本：
   - 在 v_wcnr_wfry_base 基础上增加了：
     - 性别（xyrxx_xb）
     - 身份证验证（18位+正则+日期验证+年龄<20岁？）
     - 最近一次发案年龄（从案件表取 fasj_age）
     - 现在年龄（用 birthday 字段计算）
     - 按人聚合（一人一行）：案件类型用"→"连接、立案时间链、案件编号链、案由链
     - 聚合多户籍地址、办案部门
     - 关联学校表取学校名称、年级、班级、就读状态
   - 过滤条件：录入年龄<18 + 排除特定案件编号和人员编号 + 排除特定身份证号

注意 v_wcnr_wfry_base 用的是 `zq_zfba_wcnr_xyr` 表（而非 `zq_zfba_xyrxx`），这是 WCNR（未成年违法犯罪嫌疑人）专项表。

我的 `v_wcnr_minor_detail` 视图是基于 `zq_zfba_xyrxx` 表（通用嫌疑人表）创建的，与 `v_wcnr_wfry_jbxx` 的数据源不同，但逻辑类似。

我需要给用户一个清晰的总结，说明这两个视图的区别和逻辑。