| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.goldenwater.slaj.infoquery.mapper.InfoQueryMapper">
- <!--
- 按单位查询:只查本单位和下级单位(subOrgs 递归范围)。
- 单位 = att_org_base;所辖工程 = att_eng_base.org_guid;
- 重大危险源 = obj_haz.hidd_grad='2';重大隐患 = obj_hidd.hidd_grad='2'。
- -->
- <select id="selectOrgStatList"
- parameterType="com.goldenwater.slaj.infoquery.domain.OrgStatVo"
- resultType="com.goldenwater.slaj.infoquery.domain.OrgStatVo">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- o.guid AS org_guid,
- o.org_name AS org_name,
- o.org_code AS org_code,
- e.wiun_prop AS wiun_prop,
- coalesce(stat.eng_count, 0) AS eng_count,
- coalesce(stat.major_haz_count, 0) AS major_haz_count,
- coalesce(stat.major_hidd_count, 0) AS major_hidd_count
- FROM att_org_base o
- INNER JOIN subOrgs so ON so.guid = o.guid
- LEFT JOIN att_org_ext e ON e.org_guid = o.guid
- LEFT JOIN (
- SELECT
- u.guid AS org_guid,
- count(DISTINCT eb.guid) AS eng_count,
- count(DISTINCT CASE WHEN hz.hidd_grad = '2' THEN hz.guid END) AS major_haz_count,
- count(DISTINCT CASE WHEN hd.hidd_grad = '2' THEN hd.guid END) AS major_hidd_count
- FROM att_org_base u
- LEFT JOIN att_eng_base eb ON eb.org_guid = u.guid
- LEFT JOIN obj_haz hz ON hz.org_guid = u.guid
- LEFT JOIN obj_hidd hd ON hd.org_guid = u.guid
- GROUP BY u.guid
- ) stat ON stat.org_guid = o.guid
- <where>
- <if test="orgName != null and orgName != ''">AND o.org_name LIKE '%' || #{orgName} || '%'</if>
- </where>
- ORDER BY o.org_name
- </select>
- <!-- 单位详情-工程信息:att_eng_base.org_guid = 单位 -->
- <select id="selectOrgEngList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- SELECT
- e.guid AS "guid",
- e.eng_name AS "engName",
- e.eng_type AS "engType",
- e.impo_grad AS "impoGrad",
- e.eng_stat AS "engStat",
- -- 主管单位:优先管辖单位(org_jurd),其次管理单位(org_rest)
- coalesce(oj.wiun_name, orr.wiun_name, jd.org_name, rd.org_name) AS "supOrgName"
- FROM att_eng_base e
- LEFT JOIN att_org_ext oj ON oj.org_guid = e.org_jurd
- LEFT JOIN att_org_ext orr ON orr.org_guid = e.org_rest
- LEFT JOIN att_org_base jd ON jd.guid = e.org_jurd
- LEFT JOIN att_org_base rd ON rd.guid = e.org_rest
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND e.org_guid = #{orgGuid}::text</if>
- <if test="engName != null and engName != ''">AND e.eng_name LIKE '%' || #{engName} || '%'</if>
- </where>
- ORDER BY e.coll_time DESC
- </select>
- <!-- 按工程查询列表:数据范围=本单位和下级单位(subOrgs),工程 = att_eng_base -->
- <select id="selectEngList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- e.guid AS "guid",
- e.eng_name AS "engName",
- e.eng_type AS "engType",
- e.impo_grad AS "impoGrad",
- e.eng_stat AS "engStat",
- -- 主管单位:优先管辖单位(org_jurd),其次管理单位(org_rest)
- coalesce(oj.wiun_name, orr.wiun_name, jd.org_name, rd.org_name) AS "supOrgName"
- FROM att_eng_base e
- LEFT JOIN att_org_ext oj ON oj.org_guid = e.org_jurd
- LEFT JOIN att_org_ext orr ON orr.org_guid = e.org_rest
- LEFT JOIN att_org_base jd ON jd.guid = e.org_jurd
- LEFT JOIN att_org_base rd ON rd.guid = e.org_rest
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND e.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- <if test="engName != null and engName != ''">AND e.eng_name LIKE '%' || #{engName} || '%'</if>
- <if test="engType != null and engType != ''">AND e.eng_type = #{engType}</if>
- <if test="impoGrad != null and impoGrad != ''">AND e.impo_grad = #{impoGrad}</if>
- <if test="engStat != null and engStat != ''">AND e.eng_stat = #{engStat}</if>
- </where>
- ORDER BY e.coll_time DESC
- </select>
- <!--
- 应急预案信息查询:预案 = t_busi_conplan_basic,数据范围 = 本单位和下级单位(subOrgs)。
- 评审/备案取最新一条 t_busi_review_info,公开取最新一条 t_busi_plan_disclosure,
- 周期内评估取最新一条 t_busi_regular_evalu(eva_status:1未评估 2已评估)。
- -->
- <select id="selectPlanQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- b.guid AS "guid",
- b.plan_name AS "planName",
- b.plan_type AS "planType",
- b.entry_time AS "entryTime",
- d.dept_name AS "orgName",
- rv.review_status AS "reviewStatus",
- rv.keep_status AS "keepStatus",
- ds.public_status AS "publicStatus",
- ev.eva_status AS "evaStatus"
- FROM t_busi_conplan_basic b
- LEFT JOIN sys_dept d ON d.dept_id = b.org_guid
- LEFT JOIN (
- SELECT DISTINCT ON (basic_id) basic_id, review_status, keep_status
- FROM t_busi_review_info
- ORDER BY basic_id, create_time DESC
- ) rv ON rv.basic_id = b.guid
- LEFT JOIN (
- SELECT DISTINCT ON (basic_id) basic_id, public_status
- FROM t_busi_plan_disclosure
- ORDER BY basic_id, create_time DESC
- ) ds ON ds.basic_id = b.guid
- LEFT JOIN (
- SELECT DISTINCT ON (basic_id) basic_id, eva_status
- FROM t_busi_regular_evalu
- ORDER BY basic_id, create_time DESC
- ) ev ON ev.basic_id = b.guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND b.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- <if test="planName != null and planName != ''">AND b.plan_name LIKE '%' || #{planName} || '%'</if>
- <if test="reviewStatus != null and reviewStatus != ''">AND rv.review_status = #{reviewStatus}</if>
- <if test="keepStatus != null and keepStatus != ''">AND rv.keep_status = #{keepStatus}</if>
- <if test="evaStatus != null and evaStatus != ''">AND ev.eva_status = #{evaStatus}</if>
- </where>
- ORDER BY b.create_time DESC
- </select>
- <!--
- 应急演练信息查询:演练 = t_busi_drill_record,数据范围 = 本单位和下级单位(subOrgs)。
- -->
- <select id="selectDrillQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- r.dr_guid AS "drGuid",
- r.basic_id AS "basicId",
- r.drill_name AS "drillName",
- r.drill_type AS "drillType",
- r.drill_time AS "drillTime",
- r.partake_org AS "partakeOrg",
- r.partake_num AS "partakeNum",
- b.plan_name AS "planName",
- d.dept_name AS "orgName"
- FROM t_busi_drill_record r
- LEFT JOIN t_busi_conplan_basic b ON b.guid = r.basic_id
- LEFT JOIN sys_dept d ON d.dept_id = r.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND r.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- </where>
- ORDER BY r.create_time DESC
- </select>
- <!--
- 应急队伍信息查询:队伍 = t_busi_team_info,数据范围 = 本单位和下级单位(subOrgs)。
- -->
- <select id="selectTeamQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- t.guid AS "guid",
- t.team_name AS "teamName",
- t.team_pernum AS "teamPernum",
- t.team_leader AS "teamLeader",
- t.team_res AS "teamRes",
- d.dept_name AS "orgName"
- FROM t_busi_team_info t
- LEFT JOIN sys_dept d ON d.dept_id = t.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND t.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- </where>
- ORDER BY t.create_time DESC
- </select>
- <!--
- 应急物资及装备查询(按单位汇总):物资 = t_busi_supplies_reserve,数据范围 = 本单位和下级单位(subOrgs)。
- 列表按填报机构分组,返回物资种类总数与数量总数。
- -->
- <select id="selectSuppliesQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- s.org_guid AS "orgGuid",
- d.dept_name AS "orgName",
- COUNT(DISTINCT s.material_type) AS "materialTypeTotal",
- COALESCE(SUM(s.material_num), 0) AS "materialNumTotal"
- FROM t_busi_supplies_reserve s
- LEFT JOIN sys_dept d ON d.dept_id = s.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND s.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- </where>
- GROUP BY s.org_guid, d.dept_name
- ORDER BY d.dept_name
- </select>
- <!--
- 应急物资及装备明细:点击汇总行的“详情”查看该单位具体物资记录,
- 数据范围同样限定在本单位和下级单位(scopeOrgGuid)。
- -->
- <select id="selectSuppliesDetailList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{scopeOrgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{scopeOrgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- s.guid AS "guid",
- s.material_type AS "materialType",
- s.material_name AS "materialName",
- s.material_num AS "materialNum",
- s.specs AS "specs",
- s.company AS "company",
- s.provide_time AS "provideTime",
- s.desposit_site AS "despositSite",
- d.dept_name AS "orgName"
- FROM t_busi_supplies_reserve s
- LEFT JOIN sys_dept d ON d.dept_id = s.org_guid
- WHERE s.org_guid = #{orgGuid}
- AND s.org_guid IN (SELECT guid FROM subOrgs)
- ORDER BY s.create_time DESC
- </select>
- <!--
- 预案统计分析:预案填报/演练统计 = t_busi_plan_count(各单位月度填报数据),
- 数据范围 = 本单位和下级单位(subOrgs)。
- 统计时间(yyyy-MM)按填报记录的 create_time 月份过滤。
- -->
- <select id="selectPlanStatList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- WITH RECURSIVE subOrgs AS (
- SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
- UNION ALL
- SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
- UNION ALL
- SELECT b.guid FROM att_org_base b
- INNER JOIN subOrgs s ON b.pguid = s.guid
- )
- SELECT
- p.guid AS "guid",
- p.org_guid AS "orgGuid",
- o.org_name AS "orgName",
- p.zh_plan AS "zhPlan",
- p.zx_plan AS "zxPlan",
- p.xc_plan AS "xcPlan",
- p.org_num AS "orgNum",
- p.report_plan_org AS "reportPlanOrg",
- p.org_plan_ra AS "orgPlanRa",
- p.drill_num AS "drillNum",
- p.plan_drill_ra AS "planDrillRa",
- p.create_time AS "createTime"
- FROM t_busi_plan_count p
- LEFT JOIN att_org_base o ON o.guid = p.org_guid
- LEFT JOIN att_org_ext e ON e.org_guid = p.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">
- AND p.org_guid IN (SELECT guid FROM subOrgs)
- </if>
- <if test="wiunProp != null and wiunProp != ''">AND e.wiun_prop = #{wiunProp}</if>
- <if test="orgName != null and orgName != ''">AND o.org_name LIKE '%' || #{orgName} || '%'</if>
- <if test="statMonth != null and statMonth != ''">AND left(p.create_time::text, 7) = #{statMonth}</if>
- </where>
- ORDER BY o.org_name
- </select>
- <!-- 单位详情-危险源信息:obj_haz.org_guid = 单位 -->
- <select id="selectOrgHazList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- SELECT
- h.guid AS "guid",
- o.org_name AS "orgName",
- e.eng_name AS "engName",
- h.haz_name AS "hazName",
- h.hidd_grad AS "hiddGrad",
- h.risk_grad AS "riskGrad",
- h.monitor_means AS "monitorMeans",
- h.monitor_measure AS "monitorMeasure",
- h.if_control AS "ifControl",
- h.safe_prec AS "safePrec",
- h.emer_prec AS "emerPrec",
- -- 一源一案:该危险源所属单位存在应急预案则视为已落实(无专用字段,按此口径推导)
- CASE WHEN EXISTS (SELECT 1 FROM t_busi_conplan_basic cp WHERE cp.org_guid = h.org_guid)
- THEN 'Y' ELSE 'N' END AS "oneSourceOneCase",
- h.haz_stat AS "hazStat",
- h.sup_org AS "supOrg",
- h.sup_pers AS "supPers",
- h.offi_tel AS "supPersTel",
- h.coll_time AS "collTime"
- FROM obj_haz h
- LEFT JOIN att_org_base o ON h.org_guid = o.guid
- LEFT JOIN att_eng_base e ON h.eng_guid = e.guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND h.org_guid = #{orgGuid}::text</if>
- <if test="engGuid != null and engGuid != ''">AND h.eng_guid = #{engGuid}::text</if>
- </where>
- ORDER BY h.coll_time DESC
- </select>
- <!-- 单位详情-隐患信息:obj_hidd.org_guid = 单位,关联排查/整改(最新)/验收(最新) -->
- <select id="selectOrgHiddList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- SELECT
- h.guid AS "guid",
- o.org_name AS "orgName",
- e.eng_name AS "engName",
- h.hidd_name AS "hiddName",
- bi.insp_date AS "inspDate",
- h.hidd_grad AS "hiddGrad",
- h.hidd_clas AS "hiddClas",
- h.hidd_stat AS "hiddStat",
- coalesce(rio.org_name, ri.gover_resp_wiun) AS "rectOrgName",
- ri.rect_leg_pers AS "rectLegPers",
- -- 验收单位:验收记录创建人(rec_pers)所在单位(无专用字段,按此口径推导)
- ud.dept_name AS "acceOrgName",
- ra.accep_pers AS "accepPers",
- h.coll_time AS "collTime"
- FROM obj_hidd h
- LEFT JOIN att_org_base o ON h.org_guid = o.guid
- LEFT JOIN att_eng_base e ON h.eng_guid = e.guid
- LEFT JOIN bis_hidd_inve bi ON h.insp_rec_guid = bi.guid
- LEFT JOIN (
- SELECT DISTINCT ON (hidd_guid) hidd_guid, gover_resp_wiun_guid, gover_resp_wiun, rect_leg_pers
- FROM bis_hidd_rect_impl
- ORDER BY hidd_guid, coll_time DESC
- ) ri ON ri.hidd_guid = h.guid
- LEFT JOIN att_org_base rio ON rio.guid = ri.gover_resp_wiun_guid
- LEFT JOIN (
- SELECT DISTINCT ON (hidd_guid) hidd_guid, accep_pers, rec_pers
- FROM bis_hidd_rect_acce
- ORDER BY hidd_guid, coll_time DESC
- ) ra ON ra.hidd_guid = h.guid
- LEFT JOIN sys_user u ON u.user_id = CASE WHEN ra.rec_pers ~ '^[0-9]+$' THEN ra.rec_pers::bigint ELSE NULL END
- LEFT JOIN sys_dept ud ON ud.dept_id = u.dept_id
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND h.org_guid = #{orgGuid}::text</if>
- <if test="engGuid != null and engGuid != ''">AND h.eng_guid = #{engGuid}::text</if>
- </where>
- ORDER BY h.coll_time DESC
- </select>
- <!-- 单位详情-事故信息:obj_acci.acci_wiun_guid = 单位 -->
- <select id="selectOrgAcciList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- SELECT
- a.guid AS "guid",
- a.sgdw_name || '事故' AS "acciName",
- a.acci_grad AS "acciGrad",
- a.acci_cate AS "acciCate",
- a.cas_num AS "casNum",
- a.ser_inj_num AS "serInjNum",
- a.econ_loss AS "econLoss",
- a.rep_stat AS "repStat"
- FROM obj_acci a
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND a.acci_wiun_guid = #{orgGuid}::text</if>
- <if test="engGuid != null and engGuid != ''">AND a.eng_guid = #{engGuid}::text</if>
- </where>
- ORDER BY a.occu_time DESC
- </select>
- </mapper>
|