CustomerAnalysisMapper.xml 18.4 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
1 2 3 4 5 6
<?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="cn.iocoder.yudao.module.delivery.mapper.CustomerAnalysisMapper">
    <select id="getListPage"
            parameterType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq"
            resultType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisResp">
lanbaoming's avatar
lanbaoming committed
7
        with dataTJ AS(
lanbaoming's avatar
lanbaoming committed
8 9 10 11 12 13 14 15 16 17 18
        SELECT number,name,c.id,(
        SELECT nickname from system_user where id=c.customer_service
        ) as salesman,c.customer_service as salesmanid,
        (SELECT label from system_dict_data
        where dict_type='customer_source' and value=c.source) as sourcename,
        c.source,(u_d.dept_id) as deptid,(u_d.deptName) as deptname,
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and business_time BETWEEN
        '${sdate}' AND '${edate}') AS allsumvolume,
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and business_time BETWEEN
        '${sduibidate}' AND '${eduibidate}') as allsumvolumeTb,
        <!--海运-->
lanbaoming's avatar
lanbaoming committed
19 20 21 22
        (select round(sum(charge_volume),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=1) AS sumvolume1,
        (select round(sum(charge_volume),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sduibidate}' AND '${eduibidate}' and transport_id=1) as sumvolumeTb1,
lanbaoming's avatar
lanbaoming committed
23
        <!--空运-->
lanbaoming's avatar
lanbaoming committed
24 25 26 27
        (select round(sum(charge_weight)/100,2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=3) AS sumweightV3,
        (select round(sum(charge_weight)/100,2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sduibidate}' AND '${eduibidate}' and transport_id=3) as sumweightTbV3,
lanbaoming's avatar
lanbaoming committed
28 29 30 31 32 33 34
        '4' as monthAvg,
        '5' as monthAvgTb,
        '6' as seaMonthAvg,
        '7' as seaMonthAvgTb,
        '8' as airMothAvg,
        '9' as airMothAvgTb,
        <!--重货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
35 36
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and order_type=2) as weightSumV,
lanbaoming's avatar
lanbaoming committed
37
        <!--泡货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
38 39
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and order_type=3) as phSumV,
lanbaoming's avatar
lanbaoming committed
40
        <!--控货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
41 42
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and is_cargo_control=1) as khSumV,
lanbaoming's avatar
lanbaoming committed
43
        (CASE WHEN c.is_new = 1 THEN '是' ELSE '否' END) as isFirst,
lanbaoming's avatar
lanbaoming committed
44
        (if(c.is_new = 1,c.update_time,'')) as firstDate,
lanbaoming's avatar
lanbaoming committed
45
        <!--提货率 已提货箱数除总入库总箱数-->
lanbaoming's avatar
lanbaoming committed
46
        (select sum(charge_quantity) from view_order_businesstime where customer_id = c.id and
lanbaoming's avatar
lanbaoming committed
47
        business_time BETWEEN '${sdate}' AND '${edate}') as chargequantity,
lanbaoming's avatar
lanbaoming committed
48
        (select sum(pick_num) from view_order_businesstime where customer_id = c.id and
lanbaoming's avatar
lanbaoming committed
49 50 51
        business_time BETWEEN '${sdate}' AND '${edate}') as pickquantity,
        (CASE WHEN c.is_new = 1 THEN '新客户' ELSE '旧客户' END ) as cusYjType,
        (SELECT name_zh from ecw_country where deleted=0 and id=c.country) as country,
52
        c.type, c.create_time as createtime
lanbaoming's avatar
lanbaoming committed
53 54 55 56 57
        from ecw_customer c left join (
        SELECT d.NAME as deptName,u.dept_id,u.id as userid FROM
        system_user u LEFT JOIN system_dept d ON u.dept_id = d.id
        ) AS u_d ON c.customer_service = u_d.userid
        <include refid="WherePage"/>
58 59 60
        )
        select * from dataTJ
        <include refid="WherePage2"/>
lanbaoming's avatar
lanbaoming committed
61 62 63 64 65 66 67


        <if test="orderfield!=null and orderfield!=''
         and ordertype!=null and ordertype!=''">
            order by ${orderfield} ${ordertype}
        </if>

68
        limit #{start},#{size}
lanbaoming's avatar
lanbaoming committed
69
    </select>
70 71 72

    <sql id="WherePage2">
        <where>
lanbaoming's avatar
lanbaoming committed
73 74 75 76 77 78 79 80 81
            <if test="sdate5!=null and sdate5!=''">
                <!--首次成交时间-->
                <if test="edate5!=null and edate5!=''">
                    and firstDate BETWEEN #{sdate5} AND #{edate5}
                </if>
            </if>
            <if test="searchDataType1!=null and searchDataType1!=''">
                <if test="searchData1!=null and searchData1!=''">
                    <!--总值查询-->
82
                    <choose>
lanbaoming's avatar
lanbaoming committed
83 84 85 86 87 88 89 90 91 92
                        <when test="searchDataType1 =='1'.toString()">
                            <!--大于等于的写法-->
                            and allsumvolume <![CDATA[ >= ]]> #{searchData1}
                        </when>
                        <when test="searchDataType1 =='2'.toString()">
                            and allsumvolume= #{searchData1}
                        </when>
                        <when test="searchDataType1 =='3'.toString()">
                            <!--小于等于的写法-->
                            and allsumvolume <![CDATA[ <= ]]> #{searchData1}
93 94 95 96
                        </when>
                    </choose>
                </if>
            </if>
lanbaoming's avatar
lanbaoming committed
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

            <if test="searchDataType2!=null and searchDataType2!=''">
                <if test="searchData2!=null and searchData2!=''">
                    <!--海运拼柜-->
                    <choose>
                        <when test="searchDataType2 =='1'.toString()">
                            <!--大于等于的写法-->
                            and sumvolume1 <![CDATA[ >= ]]> #{searchData2}
                        </when>
                        <when test="searchDataType2 =='2'.toString()">
                            and sumvolume1 = #{searchData2}
                        </when>
                        <when test="searchDataType2 =='3'.toString()">
                            <!--小于等于的写法-->
                            and sumvolume1 <![CDATA[ <= ]]> #{searchData2}
                        </when>
                    </choose>
                </if>
            </if>
            <if test="searchDataType3!=null and searchDataType3!=''">
                <if test="searchData3!=null and searchData3!=''">
                    <!--专线空运-->
                    <choose>
                        <when test="searchDataType3 =='1'.toString()">
                            <!--大于等于的写法-->
                            and sumweightV3 <![CDATA[ >= ]]> #{searchData3}
                        </when>
                        <when test="searchDataType3 =='2'.toString()">
                            and sumweightV3 = #{searchData3}
                        </when>
                        <when test="searchDataType3 =='3'.toString()">
                            <!--小于等于的写法-->
                            and sumweightV3 <![CDATA[ <= ]]> #{searchData3}
                        </when>
                    </choose>
                </if>
133 134 135 136
            </if>
        </where>
    </sql>

lanbaoming's avatar
lanbaoming committed
137 138
    <sql id="WherePage">
        <where>
lanbaoming's avatar
lanbaoming committed
139
            and c.deleted = 0 and c.STATUS=3
lanbaoming's avatar
lanbaoming committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
            <if test="name!=null and name!=''">
                <choose>
                    <when test="searchtype =='in'.toString()">
                        and (name like concat('%',#{name},'%') or
                        number like concat('%',#{name},'%'))
                    </when>
                    <when test="searchtype =='notin'.toString()">
                        and (name not like concat('%',#{name},'%') or
                        number not like concat('%',#{name},'%'))
                    </when>
                    <when test="searchtype =='eq'.toString()">
                        and (name= #{name} or number=#{name})
                    </when>
                    <when test="searchtype =='noeq'.toString()">
                        and (name != #{name} or number != #{name})
                    </when>
                    <otherwise>
                        and (name= #{name} or number=#{name})
                    </otherwise>
                </choose>
            </if>
lanbaoming's avatar
lanbaoming committed
161 162 163 164 165 166 167
            <if test="first!=null and first!=''">
                <!--是否首次成交-->
                and c.is_new= #{first}
            </if>
            <if test="cusYjType!=null and cusYjType!=''">
                <!--业绩类型-->
                and c.is_new= #{cusYjType}
lanbaoming's avatar
lanbaoming committed
168
            </if>
lanbaoming's avatar
lanbaoming committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

            <!--客户来源-->
            <if test="sourcestr!=null and sourcestr!=''">
                and source= #{sourcestr}
            </if>

            <if test="sourcestrs!=null and sourcestrs!=''">
                and source in ${sourcestrs}
            </if>

            <!--客户角色-->
            <if test="customerrolestr!=null and customerrolestr!=''">
                and type =#{customerrolestr}
            </if>
            <if test="customerrolestrs!=null and customerrolestrs!=''">
                and type in ${customerrolestrs}
            </if>

lanbaoming's avatar
lanbaoming committed
187
            <!-- 添加国家多选功能-->
lanbaoming's avatar
lanbaoming committed
188 189
            <if test="countrystr!=null and countrystr!=''">
                and c.country= #{countrystr}
lanbaoming's avatar
lanbaoming committed
190
            </if>
lanbaoming's avatar
lanbaoming committed
191 192
            <if test="countrystrs!=null and countrystrs!=''">
                and c.country in ${countrystrs}
lanbaoming's avatar
lanbaoming committed
193
            </if>
lanbaoming's avatar
lanbaoming committed
194 195 196 197 198

            <if test="salesmanidstr!=null and salesmanidstr!=''">
                <!--有具体的客户经理,就不算掉入公海池客户-->
                and c.is_in_open_sea=0
                and c.customer_service= #{salesmanidstr}
lanbaoming's avatar
lanbaoming committed
199
            </if>
lanbaoming's avatar
lanbaoming committed
200 201

            <if test="salesmanidstrs!=null and salesmanidstrs!=''">
lanbaoming's avatar
lanbaoming committed
202 203
                <!--有具体的客户经理,就不算掉入公海池客户-->
                and c.is_in_open_sea=0
lanbaoming's avatar
lanbaoming committed
204
                and c.customer_service in ${salesmanidstrs}
lanbaoming's avatar
lanbaoming committed
205
            </if>
lanbaoming's avatar
lanbaoming committed
206

lanbaoming's avatar
lanbaoming committed
207 208
            <if test="deptidstr!=null and deptidstr!=''">
                and u_d.dept_id= #{deptidstr}
lanbaoming's avatar
lanbaoming committed
209
            </if>
lanbaoming's avatar
lanbaoming committed
210 211 212
            <if test="deptidstrs!=null and deptidstrs!=''">
                and u_d.dept_id in ${deptidstrs}
            </if>
lanbaoming's avatar
lanbaoming committed
213 214 215 216
            <if test="sdate4!=null and sdate4!=''">
                <!--客户创建时间-->
                <if test="edate4!=null and edate4!=''">
                    and c.create_time BETWEEN #{sdate4} AND #{edate4}
lanbaoming's avatar
lanbaoming committed
217 218
                </if>
            </if>
lanbaoming's avatar
lanbaoming committed
219 220
        </where>
    </sql>
221

lanbaoming's avatar
lanbaoming committed
222
    <select id="GetCount" resultType="java.lang.Long">
lanbaoming's avatar
lanbaoming committed
223 224 225 226 227 228 229 230 231
        <!--
         SELECT count(*)
         from ecw_customer c left join (
         SELECT d.NAME as deptName,u.dept_id,u.id as userid FROM
         system_user u LEFT JOIN system_dept d ON u.dept_id = d.id
         ) AS u_d ON c.customer_service = u_d.userid
         <include refid="WherePage"/>-->
        WITH dataTJ as(
        SELECT c.id,
lanbaoming's avatar
lanbaoming committed
232
        (if(c.is_new = 1,c.update_time,'')) as firstDate,
lanbaoming's avatar
lanbaoming committed
233
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and business_time BETWEEN
lanbaoming's avatar
lanbaoming committed
234 235 236 237 238
        '${sdate}' AND '${edate}') AS allsumvolume,
        (select round(sum(charge_volume),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=1) AS sumvolume1,
        (select round(sum(charge_weight),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=3) AS sumweightV3
lanbaoming's avatar
lanbaoming committed
239 240 241 242 243
        from ecw_customer c left join (
        SELECT d.NAME as deptName,u.dept_id,u.id as userid FROM
        system_user u LEFT JOIN system_dept d ON u.dept_id = d.id
        ) AS u_d ON c.customer_service = u_d.userid
        <include refid="WherePage"/>
lanbaoming's avatar
lanbaoming committed
244 245 246 247
        )
        select count(*) from dataTJ
        <include refid="WherePage2"/>

lanbaoming's avatar
lanbaoming committed
248 249
    </select>

lanbaoming's avatar
lanbaoming committed
250 251
    <select id="getList"
            parameterType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq"
lanbaoming's avatar
lanbaoming committed
252 253 254
            resultType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisResp">
        with dataTJ AS(
        SELECT number,name,c.id,(
lanbaoming's avatar
lanbaoming committed
255 256 257 258 259 260 261 262 263 264
        SELECT nickname from system_user where id=c.customer_service
        ) as salesman,c.customer_service as salesmanid,
        (SELECT label from system_dict_data
        where dict_type='customer_source' and value=c.source) as sourcename,
        c.source,(u_d.dept_id) as deptid,(u_d.deptName) as deptname,
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and business_time BETWEEN
        '${sdate}' AND '${edate}') AS allsumvolume,
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and business_time BETWEEN
        '${sduibidate}' AND '${eduibidate}') as allsumvolumeTb,
        <!--海运-->
lanbaoming's avatar
lanbaoming committed
265 266 267 268
        (select round(sum(charge_volume),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=1) AS sumvolume1,
        (select round(sum(charge_volume),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sduibidate}' AND '${eduibidate}' and transport_id=1) as sumvolumeTb1,
lanbaoming's avatar
lanbaoming committed
269
        <!--空运-->
lanbaoming's avatar
lanbaoming committed
270 271 272 273
        (select round(sum(charge_weight)/100,2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and transport_id=3) AS sumweightV3,
        (select round(sum(charge_weight)/100,2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sduibidate}' AND '${eduibidate}' and transport_id=3) as sumweightTbV3,
lanbaoming's avatar
lanbaoming committed
274 275 276 277 278 279 280
        '4' as monthAvg,
        '5' as monthAvgTb,
        '6' as seaMonthAvg,
        '7' as seaMonthAvgTb,
        '8' as airMothAvg,
        '9' as airMothAvgTb,
        <!--重货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
281 282
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and order_type=2) as weightSumV,
lanbaoming's avatar
lanbaoming committed
283
        <!--泡货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
284 285
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and order_type=3) as phSumV,
lanbaoming's avatar
lanbaoming committed
286
        <!--控货 计算占比,不计算同步-->
lanbaoming's avatar
lanbaoming committed
287 288
        (select round(sum(vz),2) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}' and is_cargo_control=1) as khSumV,
lanbaoming's avatar
lanbaoming committed
289
        (CASE WHEN c.is_new = 1 THEN '是' ELSE '否' END) as isFirst,
lanbaoming's avatar
lanbaoming committed
290
        (if(c.is_new = 1,c.update_time,'')) as firstDate,
lanbaoming's avatar
lanbaoming committed
291 292 293 294 295 296 297
        <!--提货率 已提货箱数除总入库总箱数-->
        (select sum(charge_quantity) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}') as chargequantity,
        (select sum(pick_num) from view_order_businesstime where customer_id = c.id and
        business_time BETWEEN '${sdate}' AND '${edate}') as pickquantity,
        (CASE WHEN c.is_new = 1 THEN '新客户' ELSE '旧客户' END ) as cusYjType,
        (SELECT name_zh from ecw_country where deleted=0 and id=c.country) as country,
lanbaoming's avatar
lanbaoming committed
298
        c.type, c.create_time as createtime
lanbaoming's avatar
lanbaoming committed
299 300 301 302
        from ecw_customer c left join (
        SELECT d.NAME as deptName,u.dept_id,u.id as userid FROM
        system_user u LEFT JOIN system_dept d ON u.dept_id = d.id
        ) AS u_d ON c.customer_service = u_d.userid
lanbaoming's avatar
lanbaoming committed
303 304 305
        <include refid="WherePage"/>
        )
        select * from dataTJ
306
        <include refid="WherePage2"/>
lanbaoming's avatar
lanbaoming committed
307
        order by allsumvolume desc,number desc
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

    </select>

    <select id="getListPage_New"
            parameterType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq"
            resultType="cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisResp">
        select a.*,
        sum(voTb.vz) as allsumvolumeTb,
        sum(if(voTb.transport_id = 1, voTb.charge_volume, 0)) as sumvolumeTb1,
        sum(if(voTb.transport_id = 3, voTb.charge_weight, 0)) as sumweightTb3
        from (
        SELECT vc.number,
        vc.name,
        vc.id,
        vc.salesman,
        vc.salesmanid,
        vc.is_in_open_sea,
        vc.sourcename,
        vc.source,
        vc.deptid,
        vc.deptname,
        vc.isFirst,
        vc.firstDate,
        vc.cusYjType,
        vc.country,
        vc.countryID,
        vc.type,
        vc.createtime,
        sum(vo.vz) as allsumvolume,
        sum(if(vo.transport_id = 1, vo.charge_volume, 0)) as sumvolume1,
        sum(if(vo.transport_id = 3, vo.charge_weight, 0)) as sumweight3,
        sum(if(vo.order_type = 2, vo.vz, 0)) as weightSumV,
        sum(if(vo.is_cargo_control = 1, vo.vz, 0)) as khSumV,
        sum(if(vo.order_type = 3, vo.vz, 0)) as phSumV,
        sum(vo.charge_quantity) as charge_quantity,
        sum(vo.pick_num) as pick_num
        from view_customer_businesstime vc
        left join view_order_businesstime vo on vc.id = vo.customer_id
        where vo.business_time BETWEEN '${sdate}' and '${edate}'
        GROUP BY vc.id) as a
        left join view_order_businesstime voTb on a.id = voTb.customer_id
        and voTb.business_time BETWEEN '${sduibidate}' and '${eduibidate}'
        <include refid="WherePage_new"/>
        GROUP BY a.id
        order by a.allsumvolume desc
lanbaoming's avatar
lanbaoming committed
353
    </select>
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

    <sql id="WherePage_new">
        <where>
            <if test="isnew!=null and isnew!=''">
            </if>
            <if test="source!=null and source!=''">
                and a.source= #{source}
            </if>
            <if test="customerrole!=null and customerrole!=''">
                and a.type= #{customerrole}
            </if>
            <if test="country!=null and country!=''">
                and a.countryID= #{country}
            </if>
            <if test="salesmanid!=null and salesmanid!=''">
                <!--有具体的客户经理,就不算掉入公海池客户-->
                and a.is_in_open_sea=0
                and a.salesmanid= #{salesmanid}
            </if>
            <if test="deptid!=null and deptid!=''">
                and a.deptid= #{deptid}
            </if>
            <if test="searchDataType4!=null and searchDataType4!=''">
                <if test="sdate4!=null and sdate4!=''
                 and edate4!=null and edate4!=''">
                    <choose>
                        <when test="searchDataType4 =='1'">
                            and a.firstDate BETWEEN #{sdate4} AND #{edate4}
                        </when>
                        <when test="searchDataType4 =='0'">
                            and a.createtime BETWEEN #{sdate4} AND #{edate4}
                        </when>
                    </choose>
                </if>

            </if>

        </where>
    </sql>

lanbaoming's avatar
lanbaoming committed
394 395 396
</mapper>