StatisticsMapper.xml 19.6 KB
Newer Older
苗卫卫 committed
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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
<?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.boco.nbd.wios.flow.mapper.def.StatisticsMapper">

    <!--归档订单总数-->
    <select id="selectFiledOrderCount"  resultType="java.lang.Integer">
        select count(*) from t_order a where a.status=64 and a.type=1 and a.process_ins_id is not null and nodeFlag='199'
        <if test="nodeFlag != null ">
            and a.node_flag in
            <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                    #{nodeFlag}
            </foreach>
        </if>
        <if test="createTime != null and createTime != ''">
            <if test="timeType=='day'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m-%d')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m-%d')=#{createTime}
                    </otherwise>
                </choose>

            </if>
            <if test="timeType=='month'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m')=#{createTime}
                    </otherwise>
                </choose>
            </if>
        </if>
        <if test="oemId != null and oemId != ''">
                and a.oem_id=#{oemId}
        </if>
        <if test="oemId != null and oemId != ''">
            and a.oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
    </select>


    <!--流程中订单总数-->
    <select id="selectFlowOrderCount"  resultType="java.lang.Integer">
        select count(*) from t_order a where a.status!=64 and a.type=1 and a.process_ins_id is not null
        <if test="nodeFlag != null ">
            and a.node_flag in
            <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                #{nodeFlag}
            </foreach>
        </if>
        <if test="createTime != null and createTime != ''">
            <if test="timeType=='day'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m-%d')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m-%d')=#{createTime}
                    </otherwise>
                </choose>

            </if>
            <if test="timeType=='month'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m')=#{createTime}
                    </otherwise>
                </choose>
            </if>
        </if>
        <if test="oemId != null and oemId != ''">
            and a.oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
    </select>


    <resultMap id="StatisticsCountMap" type="java.util.HashMap">
        <result column="name" property="key" javaType="java.lang.String"/>
        <result column="num" property="value" javaType="java.lang.Integer"/>
    </resultMap>

    <!--根据节点查询订单总数-->
    <select id="getFlowOrderCount" resultType="java.lang.Integer">
        select  count(*)
          from  t_order
        where  type=1 and process_ins_id is not null  and (node_flag!=199 and status=64)=false
        <if test="oemId != null and oemId != ''">
            and oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
        <if test="nodeFlag != null ">
            and node_flag in
            <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                #{nodeFlag}
            </foreach>
        </if>
    </select>

    <!--区域根据节点查询订单总数-->
    <select id="getFlowOrderCountGroupArea" resultMap="StatisticsCountMap">
        select  area_name name,count(*) num
        from  t_order
        where  type=1 and process_ins_id is not null  and (node_flag!=199 and status=64)=false and area_id in (select id from t_region where parent_id=1)
        <if test="oemId != null and oemId != ''">
            and oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
        <if test="nodeFlag != null ">
            and node_flag in
            <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                #{nodeFlag}
            </foreach>
        </if>
        GROUP BY area_name
    </select>


    <!--派发订单总数-->
    <select id="getOrderCount" resultType="java.lang.Integer">
        select  count(*)
        from  t_order
        where  type=1 and process_ins_id is not null  and (node_flag!=199 and status=64)=false
        <if test="oemId != null and oemId != ''">
            and oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
    </select>

    <!--区域派发订单总数-->
    <select id="getOrderCountGroupArea" resultMap="StatisticsCountMap">
        select  area_name name,count(*) num
        from  t_order
        where  type=1 and process_ins_id is not null  and (node_flag!=199 and status=64)=false and area_id in (select id from t_region where parent_id=1)
        <if test="oemId != null and oemId != ''">
            and oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
        GROUP BY area_name
    </select>




    <!--省份订单总量-->
    <select id="selectProvinceOrderCount" resultType="com.boco.nbd.wios.flow.entity.vo.StatisticsProvinceVo">

        select a.province_id,a.province_name as provinceName ,count(*) as orderCount from t_order a where a.type=1 and (a.node_flag!=199 and a.status=64)=false and a.process_ins_id is not null and a.province_name is not null
        <if test="nodeFlag != null ">
            and a.node_flag in
            <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                #{nodeFlag}
            </foreach>
        </if>
        <if test="createTime != null and createTime != ''">
            <if test="timeType=='day'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m-%d')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m-%d')=#{createTime}
                    </otherwise>
                </choose>

            </if>
            <if test="timeType=='month'">
                <choose>
                    <when test="nodeName != null and nodeName != ''">
                        and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m')= #{createTime})
                    </when>
                    <otherwise>
                        and DATE_FORMAT(a.create_time,'%Y-%m')=#{createTime}
                    </otherwise>
                </choose>
            </if>
        </if>
        <if test="oemId != null and oemId != ''">
            and a.oem_id=#{oemId}
        </if>
        <if test="startTime != null and startTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
        </if>
        GROUP BY a.province_name
    </select>

    <!--地市订单总量-->
    <select id="selectAreaOrderCount" resultType="java.util.HashMap">


        <choose>
            <when test='provinceId == "20" or provinceId == "42" or provinceId == "25" or provinceId == "31" '>
                select a.city_name as regionName ,count(*) as orderCount from t_order a where  a.type=1 and (a.node_flag!=199 and a.status=64)=false and a.process_ins_id is not null and a.city_name is not null and a.province_id=#{provinceId}
                <if test="nodeFlag != null ">
                    and a.node_flag in
                    <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                        #{nodeFlag}
                    </foreach>
                </if>
                <if test="createTime != null and createTime != ''">
                    <if test="timeType=='day'">
                        <choose>
                            <when test="nodeName != null and nodeName != ''">
                                and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m-%d')= #{createTime})
                            </when>
                            <otherwise>
                                and DATE_FORMAT(a.create_time,'%Y-%m-%d')=#{createTime}
                            </otherwise>
                        </choose>

                    </if>
                    <if test="timeType=='month'">
                        <choose>
                            <when test="nodeName != null and nodeName != ''">
                                and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m')= #{createTime})
                            </when>
                            <otherwise>
                                and DATE_FORMAT(a.create_time,'%Y-%m')=#{createTime}
                            </otherwise>
                        </choose>
                    </if>
                </if>
                <if test="oemId != null and oemId != ''">
                    and a.oem_id=#{oemId}
                </if>
                <if test="startTime != null and startTime != ''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
                </if>
                GROUP BY a.city_name
            </when>
            <otherwise>
                select a.region_name as regionName ,count(*) as orderCount from t_order a where  a.type=1 and (a.node_flag!=199 and a.status=64)=false and a.process_ins_id is not null and a.region_name is not null and a.province_id=#{provinceId}
                <if test="nodeFlag != null ">
                    and a.node_flag in
                    <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                        #{nodeFlag}
                    </foreach>
                </if>
                <if test="createTime != null and createTime != ''">
                    <if test="timeType=='day'">
                        <choose>
                            <when test="nodeName != null and nodeName != ''">
                                and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m-%d')= #{createTime})
                            </when>
                            <otherwise>
                                and DATE_FORMAT(a.create_time,'%Y-%m-%d')=#{createTime}
                            </otherwise>
                        </choose>

                    </if>
                    <if test="timeType=='month'">
                        <choose>
                            <when test="nodeName != null and nodeName != ''">
                                and exists (select 1 from ACT_HI_TASKINST b where a.process_ins_id = b.PROC_INST_ID_ and b.NAME_ = #{nodeName} and date_format(b.END_TIME_ ,'%Y-%m')= #{createTime})
                            </when>
                            <otherwise>
                                and DATE_FORMAT(a.create_time,'%Y-%m')=#{createTime}
                            </otherwise>
                        </choose>
                    </if>
                </if>
                <if test="oemId != null and oemId != ''">
                    and a.oem_id=#{oemId}
                </if>
                <if test="startTime != null and startTime != ''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d')&gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d')&lt;= #{endTime}
                </if>
                GROUP BY a.region_name
            </otherwise>

        </choose>



    </select>

    <!--月度订单统计-->
    <select id="selectMonthOrderQuantity" resultType="java.util.HashMap">

        select date_format(create_time,'%Y-%m') as time,count(*) as orderCount

            FROM t_order

        where  type=1 and process_ins_id is not null

                and date_format(create_time,'%Y-%m')&gt;=#{startTime}

                and date_format(create_time,'%Y-%m')&lt;=#{endTime}

            <if test="nodeFlag != null ">
                and node_flag in
                <foreach collection="nodeFlag" item="nodeFlag" open="(" separator="," close=")">
                    #{nodeFlag}
                </foreach>
            </if>

            <if test="oemId != null and oemId != ''">
                and oem_id=#{oemId}
            </if>

        GROUP BY  date_format(create_time,'%Y-%m')

    </select>

    <!--查询节点信息-->
    <select id="getTaskInstByInstIdAndName" resultType="com.boco.nbd.wios.flow.entity.bo.TaskInstBO">

           select
                ID_ id,PROC_INST_ID_ procInstId,NAME_ name,START_TIME_ startTime,CLAIM_TIME_ claimTime,END_TIME_ endTime,DUE_DATE_ dueDate
           from ACT_HI_TASKINST

           <where>
               <if test="procInstId != null and procInstId != ''">
                   and  PROC_INST_ID_= #{procInstId}
               </if>
               <if test="nodeName != null and nodeName != ''">
                   and  NAME_ = #{nodeName}
               </if>
           </where>

           order by date_format(START_TIME_,'%Y-%m-%d %H:%i:%s') desc


    </select>


    <resultMap id="ScoreSupplierMap" type="java.util.HashMap">
        <result column="name" property="key" javaType="java.lang.String"/>
        <result column="num" property="value" javaType="java.lang.Integer"/>
    </resultMap>
    <!--根据服务商查询评分-->
    <select id="getScoreSupplierBySupplier" resultMap="ScoreSupplierMap">
        SELECT
            supplier_name name,
            FORMAT( AVG( final_score ), 2 )  num
        FROM
            t_score_supplier_v2
        <where>
            <if test="time != null and time != ''">
                and month = #{time}
            </if>
        </where>
        GROUP BY
            supplier_name

    </select>

    <!--根据区域查询评分-->
    <select id="getScoreSupplierByRegion" resultMap="ScoreSupplierMap">
        SELECT
            region_name name,
            FORMAT( AVG( final_score ), 2 ) num
        FROM
            t_score_supplier_v2
        <where>
            <if test="time != null and time != ''">
                and month = #{time}
            </if>
        </where>
        GROUP BY
	        region_name

    </select>


    <!--不满意订单数量统计-->
    <select id="getDissatisfiedOrderCount" resultType="java.lang.Integer">
        SELECT
        SUM( c.num ) num
        FROM
        (
            SELECT
                count(*) num
            FROM
                t_order a
                INNER JOIN t_order_score b ON a.id = b.order_id
                INNER JOIN ACT_HI_TASKINST d ON a.process_ins_id=d.PROC_INST_ID_
            WHERE
                a.type = 1
                AND a.process_ins_id IS NOT NULL
                AND ( a.node_flag != 199 AND a.STATUS = 64 )= FALSE
                AND ( a.know_after_sales_channel &lt;&gt; 0 OR a.know_after_sales_channel IS NULL )
                AND ( a.visit_content NOT IN ( 'APP', '预约充电', '充电慢', '墙盒功率' ) OR a.visit_content IS NULL )
                AND b.NAME = '充电评价'
                AND b.score &lt; 60
                AND a.node_flag &gt; 112
                AND left(d.NAME_,3) = '113'
                <if test="time != null and time != ''">
                AND DATE_FORMAT(d.START_TIME_,'%Y-%m') = #{time}
                </if>

        UNION ALL
            SELECT
                count(*) num
            FROM
                t_order a
                INNER JOIN ACT_HI_TASKINST d ON a.process_ins_id=d.PROC_INST_ID_
            WHERE
                a.type = 1
                AND a.process_ins_id IS NOT NULL
                AND ( a.node_flag != 199 AND a.STATUS = 64 )= FALSE
                AND a.know_after_sales_channel = 0
                AND a.node_flag &gt; 112
                AND left(d.NAME_,3) = '113'
                <if test="time != null and time != ''">
                AND DATE_FORMAT(d.START_TIME_,'%Y-%m') = #{time}
                </if>
        ) c

    </select>

    <!--安装审核通过数量-->
    <select id="getInstallationAuditPassedOrderCount" resultType="java.lang.Integer">
        SELECT
           count(*)
        FROM
            t_order a
            INNER JOIN ACT_HI_TASKINST d ON a.process_ins_id=d.PROC_INST_ID_
        WHERE
            a.type = 1
            AND a.process_ins_id IS NOT NULL
            AND ( a.node_flag != 199 AND a.STATUS = 64 )= FALSE
            AND a.node_flag > 112
            AND left(d.NAME_,3) = '113'
            <if test="time != null and time != ''">
                AND DATE_FORMAT(d.START_TIME_,'%Y-%m') = #{time}
            </if>
    </select>






</mapper>