HomepageSummaryMapper.xml 11 KB
<?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.zteits.urbanops.module.garden.dal.mysql.homepage.HomepageSummaryMapper">

    <select id="countInspectionPlanByCompanyId" resultType="java.util.Map" parameterType="java.lang.Long">
        SELECT
        SUM(CASE WHEN t.finish_state = 1 THEN 1 ELSE 0 END) AS unfinishedCount,
        SUM(CASE WHEN t.finish_state = 2 THEN 1 ELSE 0 END) AS finishedCount,
        SUM(CASE WHEN t.finish_state = 3 THEN 1 ELSE 0 END) AS invalidCount,
        SUM(CASE WHEN t.finish_state = 4 THEN 1 ELSE 0 END) AS terminatedCount,
        COUNT(1) AS totalCount
        FROM
        garden_inspection_plan t
        <where>
            t.deleted = 0
            <if test="companyId != null">
                AND t.company_id = #{companyId}
            </if>
        </where>
    </select>

    <select id="countMaintainPlanByCompanyId" resultType="java.util.Map" parameterType="java.lang.Long">
        SELECT
        SUM(CASE WHEN t.finish_state = 1 THEN 1 ELSE 0 END) AS unfinishedCount,
        SUM(CASE WHEN t.finish_state = 2 THEN 1 ELSE 0 END) AS finishedCount,
        SUM(CASE WHEN t.finish_state = 3 THEN 1 ELSE 0 END) AS invalidCount,
        SUM(CASE WHEN t.finish_state = 4 THEN 1 ELSE 0 END) AS terminatedCount,
        COUNT(1) AS totalCount
        FROM
        garden_maintain_plan t
        <where>
            t.deleted = 0
            <if test="companyId != null">
                AND t.company_id = #{companyId}
            </if>
        </where>
    </select>

    <select id="countInProgressWorkOrder" resultType="java.util.Map" parameterType="java.lang.Long">
        SELECT
        t.busi_line as busiLine,
        COUNT(1) AS totalCount
        FROM
        workorder_main_info t
        <where>
            t.deleted = 0
            AND t.buz_status != '200'
            <if test="companyId != null">
                AND t.worker_company_id = #{companyId}
            </if>
        </where>
        GROUP BY
        t.busi_line
    </select>

    <select id="countCompletedWorkOrder" resultType="java.util.Map" parameterType="java.lang.Long">
        SELECT
            CASE WHEN t.worker_id IS NOT NULL THEN 'validOrder'
                 ELSE 'invalidOrder'
                END AS workorder_valid_status,
            COUNT(1) AS totalCount
        FROM
            workorder_main_info t
        <where>
            t.deleted = 0
            AND t.buz_status = '200'
            <if test="companyId != null">
                AND t.worker_company_id = #{companyId}
            </if>
        </where>
        GROUP BY
            CASE WHEN t.worker_id IS NOT NULL THEN 'validOrder'
                 ELSE 'invalidOrder'
                END
    </select>
    <!--    巡查计划次数统计-->
    <select id="countInspectionPlanNumByBusiLine"  resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.CommitTaskStatisticsRespVo">
        select v.date_value dateValue,
               busi_line as busiLine ,
               IFNULL(SUM(plan_num), 0) AS inspectionPlanNum,
               IFNULL(sum(plan_finish_num),0) AS inspectionPlanFinishNum
        from view_statics_times v
        left join garden_inspection_plan_detail t
        on v.date_value = DATE_FORMAT(t.end_time , '%Y-%m-%d') and deleted =0 and finish_state NOT IN (3, 4)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
        <where>
            <if test="beginTime != null and beginTime != ''">
                AND v.date_value >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND v.date_value &lt;  #{endTime}
            </if>
        </where>
        group by  v.date_value,busi_line
    </select>
    <!--    养护计划次统计-->
    <select id="countMaintainPlanNumByBusiLine"  resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.CommitTaskStatisticsRespVo">
         select v.date_value,
                busi_line as busiLine ,
                IFNULL(SUM(plan_num), 0) AS maintainPlanNum,
                IFNULL(sum(plan_finish_num),0) as maintainPlanFinishNum
         from view_statics_times v
         left join garden_maintain_plan_detail t
         on v.date_value = DATE_FORMAT(t.end_time , '%Y-%m-%d') and busi_line='yl' and deleted =0 and finish_state NOT IN (3, 4)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
        <where>
            <if test="beginTime != null and beginTime != ''">
                AND v.date_value >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND v.date_value &lt;  #{endTime}
            </if>
        </where>
         group by  v.date_value,busi_line
    </select>

    <select id="countRatioByOrderType" resultType="java.util.Map">
        SELECT
        t.order_type AS orderType,
        COUNT(1) AS totalCount
        FROM
        workorder_main_info t
        <where>
             deleted = 0
            <if test="companyId != null">
               and t.worker_company_id = #{companyId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND t.create_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND t.create_time &lt; #{endTime}
            </if>
        </where>
        GROUP BY
        t.order_type
    </select>
    <select id="countRatioBySourceId" resultType="java.util.Map">
        SELECT
        t.source_id as sourceId,
        COUNT(1) AS totalCount
        FROM
        workorder_main_info t
        <where>
            deleted = 0
            <if test="companyId != null">
                and t.worker_company_id = #{companyId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND t.create_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND t.create_time &lt; #{endTime}
            </if>
        </where>
        GROUP BY
        t.source_id
    </select>
    <select id="countRatioByPressingType" resultType="java.util.Map" >
        SELECT
        t.pressing_type as pressingType,
        COUNT(1) AS totalCount
        FROM
        workorder_main_info t
        <where>
            deleted = 0
            <if test="companyId != null">
                and t.worker_company_id = #{companyId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND t.create_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND t.create_time &lt; #{endTime}
            </if>
        </where>
        GROUP BY
        t.pressing_type
    </select>
    <select id="countWorkOrderDistribution" resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.CommitWorkOrderRespVo">
        SELECT
        t.worker_company_id as companyId ,
        sum(case when t.order_type='Q' or t.order_type='C' then 1 else 0 end) as patrolWorkOrde,
        sum(case when t.order_type='A' then 1 else 0 end) as aiWorkOrde,
        sum(case when t.order_type='W' then 1 else 0 end) as gridWorkOrder,
        sum(case when t.order_type='O' then 1 else 0 end) as outhWorkOrderO
        FROM
        workorder_main_info t
        <where>
            deleted = 0
            <if test="companyId != null">
                and t.worker_company_id = #{companyId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND t.create_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND t.create_time &lt; #{endTime}
            </if>
        </where>
        GROUP BY
         t.worker_company_id
    </select>
    <select id="countWorkOrderDistributionBySource" resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.CommitWorkOrderSourceRespVo">
        SELECT
        t.worker_company_id AS companyId,
        -- source_id=1:巡查工单
        SUM(CASE WHEN t.source_id = 1 THEN 1 ELSE 0 END) AS patrolCount,
        -- source_id=2:游客居民工单
        SUM(CASE WHEN t.source_id = 2 THEN 1 ELSE 0 END) AS touristResidentCount,
        -- source_id=3:12345工单
        SUM(CASE WHEN t.source_id = 3 THEN 1 ELSE 0 END) AS otherCount,
        -- source_id=4:网格工单
        SUM(CASE WHEN t.source_id = 4 THEN 1 ELSE 0 END) AS gridCount,
        -- source_id=5:大区经理工单
        SUM(CASE WHEN t.source_id = 5 THEN 1 ELSE 0 END) AS regionalManagerCount,
        -- source_id=6:AI工单
        SUM(CASE WHEN t.source_id = 6 THEN 1 ELSE 0 END) AS aiCount
        FROM
        workorder_main_info t
        <where>
            deleted = 0
            <if test="companyId != null">
                and t.worker_company_id = #{companyId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND t.create_time >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND t.create_time &lt; #{endTime}
            </if>
        </where>
        GROUP BY
        t.worker_company_id
    </select>
    <!--热量图-->
    <select id="countWorkOrderHeatmap"  resultType="java.util.Map" >
        SELECT
        t.lat, t.lon, COUNT(1) AS totalCount
        FROM
        workorder_main_info t
        <where>
            t.deleted = 0
            <if test="companyId != null">
                and t.worker_company_id = #{companyId}
            </if>
        </where>
        GROUP BY
        t.lat,t.lon
    </select>

    <select id="countWorkOrderTrend" resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.WorkOrderTrendRespVo">
        select v.date_value as dateValue,
        t.busi_line as busiLine,
        t.worker_company_id as companyId,
        <choose>
            <when test='queryState != null and queryState eq "1"'>
                sum(case when v.date_value = DATE_FORMAT(t.create_time , '%Y-%m-%d') then 1 else 0 end) as totalCount
            </when>
            <when test='queryState != null and queryState eq "2"'>
                sum(case when t.buz_status != '200' then 1 else 0 end) as totalCount
            </when>
            <when test='queryState != null and queryState eq "3"'>
                sum(case when t.buz_status = '200' then 1 else 0 end) as totalCount
            </when>
        </choose>
        from view_statics_times v
        left join workorder_main_info t
        on v.date_value = DATE_FORMAT(t.create_time , '%Y-%m-%d') and deleted =0
        <if test="companyId != null">
            and t.worker_company_id = #{companyId}
        </if>
        <where>
            <if test="beginTime != null and beginTime != ''">
                AND v.date_value >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND v.date_value &lt; #{endTime}
            </if>
        </where>
        group by v.date_value,t.busi_line,t.worker_company_id
    </select>

</mapper>