zss
2024-12-27 ebede85283906f52dd45d0755d22140538038ac3
cnas-server/src/main/resources/mapper/StructureItemParameterMapper.xml
@@ -4,7 +4,9 @@
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yuanchu.mom.mapper.StructureItemParameterMapper">
    <delete id="removeNoSample">
        delete from structure_item_parameter where sample like concat('%',#{sample},'%')
        delete
        from structure_item_parameter
        where sample like concat('%', #{sample}, '%')
    </delete>
    <select id="selectItemParameterList" resultType="com.yuanchu.mom.pojo.StructureItemParameter">
        select * from (select A.id,
@@ -42,6 +44,7 @@
        WHEN INSTR(sample, ',') > 0 THEN
        SUBSTRING_INDEX(SUBSTRING_INDEX(sample, '","', 1), '"', -1)
        when sample = '[""]' then null
        when sample = '[]' then null
        ELSE
        TRIM(BOTH '["]' FROM SUBSTRING_INDEX(REPLACE(sample, '[["', ''), '"]]', 1))
        END AS samples
@@ -54,24 +57,75 @@
        WHEN code IS NULL THEN 1
        ELSE 0
        END,
        CAST(code AS UNSIGNED) asc
        CAST(code AS UNSIGNED),
        case when man_hour_group is NULL then 1
        when man_hour_group ='' then 1 else 0 end,
        CASE
        WHEN man_hour_group REGEXP '^[0-9]' THEN CAST(man_hour_group AS UNSIGNED) -- 如果以数字开头,则按照数字大小排序
        WHEN man_hour_group REGEXP '[0-9]+' THEN CAST(SUBSTRING(man_hour_group, 2)AS UNSIGNED) END -- 提取字母后面的数字部分
        ,id asc
    </select>
    <resultMap id="getInsProductions" type="map">
        <result property="name" column="inspection_item"/>
        <result property="name" column="sample"/>
        <collection property="children" resultMap="seProInsListByIdmaps" javaType="List"/>
    </resultMap>
    <resultMap id="seProInsListByIdmaps" type="map">
        <result property="name" column="inspection_item"/>
        <collection property="children" resultMap="seProInsListByIdmaps2" javaType="List"/>
    </resultMap>
    <resultMap id="seProInsListByIdmaps2" type="map">
        <id property="id" column="id"/>
        <result property="name" column="subclass"/>
    </resultMap>
    <select id="getInsProduction" resultMap="getInsProductions">
        select id,
               inspection_item,
               case
                   when inspection_item_subclass is null then inspection_item
                   else inspection_item_subclass end as subclass
        from structure_item_parameter
        WITH expanded_sample AS (
            SELECT
                id,
                CASE
                    WHEN INSTR(sample, '","') > 0 THEN
                        SUBSTRING_INDEX(SUBSTRING_INDEX(sample, '","', 1), '"', -1)
                    when sample = '[]' then '*'
                    WHEN INSTR(sample, '"],["') > 0 THEN
                        TRIM(BOTH '["]' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(sample, '"],["', 1), '"', -1))
                    ELSE
                        TRIM(BOTH '["]' FROM SUBSTRING_INDEX(REPLACE(sample, '[["', ''), '"]]', 1))
                    END
                        AS component1,
                CASE
                    WHEN INSTR(sample, '"],["') > 0 THEN
                        TRIM(BOTH '["]' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(sample, '"],["', -1), '"', 1))
                    ELSE
                        NULL
                    END AS component2,
                inspection_item,
                CASE
                    WHEN inspection_item_subclass IS NULL THEN inspection_item
                    ELSE inspection_item_subclass
                    END AS subclass
            FROM
                structure_item_parameter
        )
        SELECT
            id,
            CASE
                WHEN component1 IS NOT NULL THEN component1
                ELSE '*'
                END AS sample,
            inspection_item,
            subclass
        FROM
            expanded_sample
        UNION ALL
        SELECT
            id,
            component2 AS sample,
            inspection_item,
            subclass
        FROM
            expanded_sample
        WHERE
            component2 IS NOT NULL;
    </select>
    <select id="getItemTree" resultMap="itemDto">
        select sto.id sId, sto.specimen_name sName, p.id pId, p.name pName