HomepageSummaryMapper.xml 16.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
<?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>

    <!--已完成任务数量-->
    <select id="countcompletedTask"  resultType="com.zteits.urbanops.module.garden.controller.app.homepage.vo.TaskCompletionStatusRspVo">
        -- 按日期分组,汇总巡检+养护计划提交总数
        SELECT
        commit_date AS commitDate,
        SUM(commit_count) AS completedNum
        FROM (
        SELECT
        DATE_FORMAT(finish_time,'%Y-%m-%d') AS commit_date,
        COUNT(id) AS commit_count
        FROM garden_inspection_plan_commit
        WHERE user_id = #{userId}
        <if test="beginTime != null and beginTime != ''">
            AND finish_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND finish_time &lt; #{endTime}
        </if>
        GROUP BY DATE_FORMAT(finish_time,'%Y-%m-%d')
        UNION ALL
        SELECT
        DATE_FORMAT(finish_time,'%Y-%m-%d') AS commit_date,
        COUNT(id) AS commit_count
        FROM garden_maintain_plan_commit
        WHERE user_id = #{userId}
        <if test="beginTime != null and beginTime != ''">
            AND finish_time >= #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND finish_time &lt; #{endTime}
        </if>
        GROUP BY DATE_FORMAT(finish_time,'%Y-%m-%d')
        ) AS temp_total
        GROUP BY commit_date
        ORDER BY commit_date;
    </select>
    <!--未完成任务数量-->
    <select id="countpendingTask"  resultType="com.zteits.urbanops.module.garden.controller.app.homepage.vo.TaskCompletionStatusRspVo" >
        -- 按日期分组,汇总巡检+养护计划未完成/已过期任务总数
        SELECT
             commit_date AS commitDate,
             SUM(unfinished_count) AS countpendingNum
        FROM (
        SELECT
            DATE_FORMAT(a.begin_time, '%Y-%m-%d') AS commit_date,
            COUNT(*) AS unfinished_count
        FROM
            garden_inspection_plan_detail a
        INNER JOIN garden_inspection_plan_role b ON a.batch_no = b.batch_no
        WHERE a.finish_state IN (1, 3)  -- 1:未完成;3:已过期
        AND b.role_id IN
            <foreach collection='roleIds' item='roleId' open='(' close=')' separator=','>
             #{roleId}
            </foreach>
        <if test="beginTime != null and beginTime != ''">
            AND a.begin_time  >= #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND a.end_time &lt; #{endTime}
        </if>
        GROUP BY
            DATE_FORMAT(a.begin_time, '%Y-%m-%d')

        UNION ALL

        SELECT
            DATE_FORMAT(a.begin_time, '%Y-%m-%d') AS commit_date,
            COUNT(*) AS unfinished_count
        FROM
            garden_maintain_plan_detail a
        INNER JOIN garden_maintain_plan_role b ON a.batch_no = b.batch_no
        WHERE a.finish_state IN (1, 3)  -- 1:未完成;3:已过期
            AND b.role_id IN
            <foreach collection='roleIds' item='roleId' open='(' close=')' separator=','>
                #{roleId}
            </foreach>
            <if test="beginTime != null and beginTime != ''">
                AND a.begin_time  >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND a.end_time &lt; #{endTime}
            </if>
        GROUP BY
             DATE_FORMAT(a.begin_time, '%Y-%m-%d')
        ) AS temp_total
        GROUP BY
            commit_date
        ORDER BY
            commit_date;
    </select>
    <!--已完成任务详情-->
    <select id="queryCompletedTaskDetails"  resultType="com.zteits.urbanops.module.garden.controller.app.homepage.vo.TaskDetailsRspVo" >
        -- 巡查已办理
        SELECT taskName, busiDateTime, pressingType
        FROM (
            SELECT B.plan_name as taskName,A.finish_time as busiDateTime
            from garden_inspection_plan_commit a , garden_inspection_plan b
            where a.batch_no=b.batch_no  and  user_id = #{userId}
            union all
            -- 养护已办理
            SELECT b.plan_name as taskName,a.finish_time as busiDateTime
            from garden_maintain_plan_commit a , garden_maintain_plan  b
            where a.batch_no=b.batch_no  and user_id = #{userId}
             ) t
        ORDER BY busiDateTime DESC
    </select>
    <!--待办任务详情-->
    <select id="queryPendingTaskDetails"  resultType="com.zteits.urbanops.module.garden.controller.app.homepage.vo.TaskDetailsRspVo" >
        SELECT taskName, busiDateTime, pressingType
        FROM (
                 SELECT a.plan_name as taskName,a.begin_time as busiDateTime
                 from garden_inspection_plan a
                          INNER JOIN  garden_inspection_plan_role b  on a.batch_no=b.batch_no
                 where a.finish_state in(1,3)
                        AND b.role_id IN
                        <foreach collection='roleIds' item='roleId' open='(' close=')' separator=','>
                            #{roleId}
                        </foreach>
                 union all
                 SELECT a.plan_name as taskName,a.begin_time as busiDateTime
                 from garden_maintain_plan a
                          INNER JOIN  garden_maintain_plan_role b  on a.batch_no=b.batch_no
                 where a.finish_state in(1,3)
                        AND b.role_id IN
                        <foreach collection='roleIds' item='roleId' open='(' close=')' separator=','>
                            #{roleId}
                        </foreach>
             ) t
        ORDER BY busiDateTime DESC
    </select>
</mapper>