| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?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.yt.zhylplat.moduleLhgy.mapper.TLhgyWorkPlanMapper">
- <select id="selectWorkPlanBySection" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select
- temp_rsmc.old_section_id as sectionId,
- temp_rsmc.section_name as section_code,
- temp_rsmc.old_maintenance_company_id as objectId,
- temp_rsmc.maintenance_company_name as object_name,
- temp_rsmc.section_type,
- temp_rsmc.section_id as newSectionId,
- temp_rsmc.maintenance_company_id as maintenance_company_id,
- if(temp.planCount is null, 0, temp.planCount) as planCount,
- if(temp.noCompleteCount is null, 0, temp.noCompleteCount) as noCompleteCount,
- if(temp.completeCount is null, 0, temp.completeCount) as completeCount
- from
- (
- SELECT DISTINCT
- rsmc.section_id,
- s.section_name,
- s.section_type,
- rsmc.maintenance_company_id,
- mc.maintenance_company_name,
- s.old_section_id,
- mc.old_maintenance_company_id
- FROM
- T_Lhzx_Road_Section_Maintenance_Company rsmc
- LEFT JOIN
- T_Lhzx_Section s ON rsmc.section_id = s.id
- LEFT JOIN
- T_Lhzx_Maintenance_Company mc on rsmc.maintenance_company_id = mc.id
- ) temp_rsmc
- left join
- (<include refid="selectWorkPlanSql"/>) temp
- on temp_rsmc.section_id = temp.newSectionId and temp_rsmc.maintenance_company_id = temp.maintenance_company_id
- </select>
- <select id="selectWorkPlanBySectionType" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select distinct
- s.section_type,
- sum(if(temp.planCount is null, 0, temp.planCount)) as planCount,
- sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount)) as noCompleteCount,
- sum(if(temp.completeCount is null, 0, temp.completeCount)) as completeCount
- from
- T_Lhzx_Section s
- left join
- (<include refid="selectWorkPlanSql"/>) temp
- on
- s.section_type = temp.section_type
- group by
- s.section_type
- </select>
- <select id="selectWorkPlanSumCount" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select
- if(sum(if(temp.planCount is null, 0, temp.planCount)) is null, 0, sum(if(temp.planCount is null, 0, temp.planCount))) as planCount,
- if(sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount)) is null, 0, sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount))) as noCompleteCount,
- if(sum(if(temp.completeCount is null, 0, temp.completeCount)) is null, 0, sum(if(temp.completeCount is null, 0, temp.completeCount))) as completeCount
- from
- (<include refid="selectWorkPlanSql"/>) temp
- </select>
- <select id="selectWorkPlanComRateBySection" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select
- temp.*
- from
- (<include refid="workPlanComRateSql"/>) temp
- </select>
- <select id="selectWorkPlanComRateByTrimType" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select
- temp.trim_type,
- SUM(IF(temp.planCount is null, 0, temp.planCount)) as planCount,
- SUM(IF(temp.completeCount is null,0,temp.completeCount)) as completeCount,
- SUM(IF(temp.completeCount is null,0,temp.completeCount)) / SUM(IF(temp.planCount is null, 0, temp.planCount)) as complete_rate
- from
- (<include refid="workPlanComRateSql"/>) temp
- group by
- temp.trim_type
- </select>
- <select id="selectLhgyPlanByPageList" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
- select * from T_Lhgy_Work_Plan p left join (
- select
- plan_id,
- trim_type
- FROM
- T_Lhgy_Work_Plan_Detail
- where
- state=2
- and
- delete_flag=0
- <if test="tLhgyWorkPlan.trimType != null">
- and trim_type=#{tLhgyWorkPlan.trimType}
- </if>
- GROUP BY plan_id,trim_type ORDER BY plan_id) pd
- on p.id=pd.plan_id
- where p.state=2
- and p.delete_flag=0
- <if test="tLhgyWorkPlan.planType != null">
- and p.plan_type = #{tLhgyWorkPlan.planType}
- </if>
- <if test="tLhgyWorkPlan.sectionId != null">
- and p.section_id = #{tLhgyWorkPlan.sectionId}
- </if>
- <if test="tLhgyWorkPlan.objectId != null">
- and p.object_id = #{tLhgyWorkPlan.objectId}
- </if>
- order by
- p.id
- </select>
- <sql id="workPlanComRateSql">
- SELECT
- wp.section_id,
- s.section_name as section_code,
- wp.object_id,
- mc.maintenance_company_name as object_name,
- wpd.trim_type,
- SUM(IF(wpd.amount is null, 0, wpd.amount)) as planCount,
- SUM(IF(wpdi.complete_amount is null,0,wpdi.complete_amount)) as completeCount,
- SUM(IF(wpdi.complete_amount is null,0,wpdi.complete_amount)) / SUM(IF(wpd.amount is null, 0, wpd.amount)) as complete_rate
- FROM
- T_Lhgy_Work_Plan_Detail wpd
- LEFT JOIN
- T_Lhgy_Work_Plan wp ON wp.id = wpd.plan_id
- left join
- T_Lhzx_Section s on wp.section_id = s.old_section_id
- left join
- T_Lhzx_Maintenance_Company mc on mc.old_maintenance_company_id = wp.object_id
- LEFT JOIN (
- SELECT
- SUM(IF(complete_amount is null,0,complete_amount)) as complete_amount,
- plan_detail_id
- FROM
- T_Lhgy_Work_Plan_Detail_Item
- WHERE
- delete_flag = 0
- GROUP BY
- plan_detail_id
- ) wpdi on wpd.id = wpdi.plan_detail_id
- LEFT JOIN (
- SELECT
- sum(
- if(extra_large_num is null, 0, extra_large_num) +
- if(large_num is null, 0, large_num) +
- if(medium_num is null, 0, medium_num) +
- if(small_num is null, 0, small_num)
- ) as total_amount,
- mc.old_maintenance_company_id,
- s.old_section_id,
- road_id
- FROM
- T_Lhzx_Street_Tree st
- LEFT JOIN T_Lhzx_Maintenance_Company mc on mc.id = st.maintenance_company_id
- LEFT JOIN T_Lhzx_Section s on s.id = st.section_id
- WHERE
- st.del_flg = 0
- GROUP BY
- maintenance_company_id,
- section_id,
- road_id
- ) st on st.road_id = wpd.number5 and st.old_section_id = wp.section_id and st.old_maintenance_company_id = wp.object_id
- WHERE
- wpd.delete_flag = 0
- <if test="tLhgyWorkPlan.trimType != null and tLhgyWorkPlan.trimType == 4">
- and (wpd.trim_type = 4 or wp.plan_type = 2)
- </if>
- <if test="tLhgyWorkPlan.trimType != null and tLhgyWorkPlan.trimType != 4">
- and wpd.trim_type = #{tLhgyWorkPlan.trimType}
- </if>
- <if test="tLhgyWorkPlan.sectionId != null">
- and wp.section_id = #{tLhgyWorkPlan.sectionId}
- </if>
- <if test="tLhgyWorkPlan.objectId != null">
- and wp.object_id = #{tLhgyWorkPlan.objectId}
- </if>
- <if test="tLhgyWorkPlan.planYear != null and tLhgyWorkPlan.planYear != ''">
- and DATE_FORMAT(wpd.create_date, '%Y') = #{tLhgyWorkPlan.planYear}
- </if>
- and
- wpd.trim_type is not null
- and
- wp.section_id is not null
- GROUP BY
- wp.section_id,
- wp.section_code,
- wp.object_id,
- wp.object_name,
- wpd.trim_type,
- s.id,
- mc.id
- order by
- s.id,
- mc.id
- </sql>
- <sql id="selectWorkPlanSql">
- select
- wp.section_id as sectionId,
- s.section_name as section_code,
- wp.object_id as objectId,
- mc.maintenance_company_name as object_name,
- s.section_type,
- s.id as newSectionId,
- mc.id as maintenance_company_id,
- count(wp.id) as planCount,
- sum(if(wp.comp_state = 1, 1, 0)) as noCompleteCount,
- sum(if(wp.comp_state = 2, 1, 0)) as completeCount
- from
- T_Lhgy_Work_Plan wp
- left join
- T_Lhzx_Section s on s.old_section_id = wp.section_id
- left join
- T_Lhzx_Maintenance_Company mc on mc.old_maintenance_company_id = wp.object_id
- where
- wp.delete_flag = 0
- <if test="tLhgyWorkPlan.sectionId != null">
- and wp.section_id = #{tLhgyWorkPlan.sectionId}
- </if>
- <if test="tLhgyWorkPlan.objectId != null">
- and wp.object_id = #{tLhgyWorkPlan.objectId}
- </if>
- <if test="tLhgyWorkPlan.planMonth != null and tLhgyWorkPlan.planMonth != ''">
- and DATE_FORMAT(wp.create_date, '%Y-%m') = #{tLhgyWorkPlan.planMonth}
- </if>
- <if test="tLhgyWorkPlan.sectionType != null">
- and s.section_type = #{tLhgyWorkPlan.sectionType}
- </if>
- <if test="tLhgyWorkPlan.trimType != null">
- and wp.id in (
- select
- plan_id
- from
- T_Lhgy_Work_Plan_Detail
- where
- delete_flag = 0
- and
- trim_type = #{trimType}
- )
- </if>
- group by
- wp.section_id,
- s.section_name,
- wp.object_id,
- mc.maintenance_company_name,
- s.section_type,
- s.id,
- mc.id
- order by
- s.id,
- mc.id
- </sql>
- </mapper>
|