| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?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.ydtech.modules.admin.dao.TaskStatisticsMapper">
- <select id="getBusinessAgentData" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
- select
- su.id as "userId",
- su.name as "userName",
- sd.id as "deptId",
- su.leader_name as "leaderName",
- IFNULL(a.sumpremium,0) as "sumpremium",
- IFNULL(a.jqpremium,0) as "jqpremium",
- IFNULL(a.sypremium,0) as "sypremium",
- IFNULL(a.taxamount,0) as "taxamount",
- IFNULL(a.jypremium,0) as "jypremium",
- IFNULL(a.riskCodeJs,0) as "riskCodeJs",
- IFNULL(a.riskCodeDj,0) as "riskCodeDj" ,
- IFNULL(a.riskCodeJshang,0) as "riskCodeJshang",
- IFNULL(a.riskCodeDs,0) as "riskCodeDs",
- IFNULL(a.riskCodeDsan,0) as "riskCodeDsan",
- sd.management_source as "managementSource",
- IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0) as "distributionAmount",
- (IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)) / a.sumpremium as "distributionAmountRate"
- from sys_user su
- left join sys_dept sd on sd.id =su.dept_id
- LEFT JOIN sys_user_role sur ON sur.user_id = su.id
- left join (
- select
- io.userid as "userId",
- sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
- IFNULL(sum(jqpremium),0) as "jqpremium",
- IFNULL(sum(sypremium),0) as "sypremium",
- IFNULL(sum(taxamount),0) as "taxamount",
- IFNULL(sum(jypremium),0) as "jypremium",
- COUNT( CASE WHEN iac.product = '交三' THEN 1 END ) AS "riskCodeJs",
- COUNT( CASE WHEN iac.product = '单交' THEN 1 END ) AS "riskCodeDj",
- COUNT( CASE WHEN iac.product = '交商' THEN 1 END ) AS "riskCodeJshang",
- COUNT( CASE WHEN iac.product = '单商' THEN 1 END ) AS "riskCodeDs",
- COUNT( CASE WHEN iac.product = '单三' THEN 1 END ) AS "riskCodeDsan",
- ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
- (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
- ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
- +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
- +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
- from ins_area_company iac
- left join ins_orders io on io.orderno =iac.orderno
- left join sys_user su on su.id =io.userid
- LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
- <where>
- iac.orderstatus = '3'
- <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d')
- AND DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.leader_id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </where>
- group by io.userid
- ) a on a.userId =su.id
- <where>
- 1=1
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.userName !=null and vo.userName!=''">
- and su.name=#{vo.userName}
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.leader_id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <choose>
- <when test='vo.managementSource == "2"'>
- and (sur.role_id = 20 or sur.role_id = 21)
- </when>
- <when test='vo.managementSource == "1"'>
- and (sur.role_id = 19 or sur.role_id = 21)
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
- AND sd.id in
- <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.deptId !=null and vo.deptId!=''">
- and sd.id like concat('%',#{vo.deptId},'%')
- </if>
- </where>
- order by a.sumpremium desc ,su.id
- </select>
- <select id="getBusinessAgentDataTotal" resultType="java.lang.Long">
- select
- COUNT(0)
- from sys_user su
- left join sys_dept sd on sd.id =su.dept_id
- LEFT JOIN sys_user_role sur ON sur.user_id = su.id
- <where>
- 1=1
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.leader_id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.userName !=null and vo.userName!=''">
- and su.name=#{vo.userName}
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
- AND sd.id in
- <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.deptId !=null and vo.deptId!=''">
- and sd.id like concat('%',#{vo.deptId},'%')
- </if>
- <choose>
- <when test='vo.managementSource == "2"'>
- and (sur.role_id = 20 or sur.role_id = 21)
- </when>
- <when test='vo.managementSource == "1"'>
- and (sur.role_id = 19 or sur.role_id = 21)
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </where>
- </select>
- <select id="getBusinessAgentDataTotalAdd" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
- select
- sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
- IFNULL(sum(jqpremium),0) as "jqpremium",
- IFNULL(sum(sypremium),0) as "sypremium",
- IFNULL(sum(taxamount),0) as "taxamount",
- IFNULL(sum(jypremium),0) as "jypremium",
- ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
- (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
- ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
- +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
- +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
- from ins_area_company iac
- left join ins_orders io on io.orderno =iac.orderno
- left join sys_user su on io.userid =su.id
- left join sys_dept sd on sd.id =su.dept_id
- LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
- <where>
- iac.orderstatus = '3'
- <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
- DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
- </if>
- <if test="vo.days !=null and vo.days !='' and vo.days != 0 ">
- and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
- </if>
- <if test="vo.userName !=null and vo.userName!=''">
- and su.name=#{vo.userName}
- </if>
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.leader_id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.deptId !=null and vo.deptId!=''">
- and io.deptid like concat('%',#{vo.deptId},'%')
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
- AND io.deptid in
- <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <select id="getAllsumPremium" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
- select
- sum(IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0)+ IFNULL(iac.jypremium, 0)) as "sumpremium"
- from ins_area_company iac
- left join ins_orders io on io.orderno =iac.orderno
- left join sys_user su on io.userid =su.id
- left join sys_dept sd on sd.id =su.dept_id
- <where>
- 1=1
- <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
- DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
- </if>
- <if test="vo.userName !=null and vo.userName!=''">
- and su.name=#{vo.userName}
- </if>
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.proportionUserIds !=null and vo.proportionUserIds!='' and vo.proportionUserIds.size()>0">
- and su.id in
- <foreach collection="vo.proportionUserIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.leader_id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
- AND io.deptid in
- <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <select id="getBusinessAgentDataDetails" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
- select
- a.insurance_company as "insuranceCompany",
- (IFNULL(a.jqpremium, 0) + IFNULL(a.sypremium, 0)+ IFNULL(a.jypremium, 0)) as "sumpremium",
- a.jqpremium as "jqpremium",
- a.sypremium as "sypremium",
- a.taxamount as "taxamount",
- a.jypremium as "jypremium",
- eic.namesimple as "partnerCompaniesName",
- eic.logo as "logo",
- a.userId as "userId",
- a.userName as "userName"
- from (select pa.insurance_company,
- pa.partner_companies_id,
- su.id as "userId",
- su.name as "userName",
- IFNULL(sum(sumpremium), 0) as "sumpremium",
- IFNULL(sum(jqpremium), 0) as "jqpremium",
- IFNULL(sum(sypremium), 0) as "sypremium",
- IFNULL(sum(taxamount), 0) as "taxamount",
- IFNULL(sum(jypremium), 0) as "jypremium"
- from ins_area_company iac
- left join ins_orders io on io.orderno = iac.orderno
- left join ptl_agreement pa on pa.id = iac.agreement_id
- left join sys_user su on io.userid =su.id
- left join sys_dept sd on sd.id =su.dept_id
- LEFT JOIN esm_ins_company eic on eic.id = pa.partner_companies_id
- <where>
- iac.orderstatus = '3'
- and io.orderstatus = '3'
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
- DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
- and su.id in
- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </where>
- group by pa.insurance_company, pa.partner_companies_id ,su.id,su.name) a
- LEFT JOIN esm_ins_company eic ON eic.id = a.partner_companies_id
- </select>
- <select id="getBusinessAgentDataDetailsAdd" resultType="java.lang.Long">
- select
- count(0)
- from (select pa.insurance_company,
- pa.partner_companies_id
- from ins_area_company iac
- left join ins_orders io on io.orderno = iac.orderno
- left join ptl_agreement pa on pa.id = iac.agreement_id
- left join sys_user su on io.userid =su.id
- <where>
- iac.orderstatus = '3'
- and io.orderstatus = '3'
- <if test="vo.userId !=null and vo.userId!=''">
- and su.id=#{vo.userId}
- </if>
- <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
- DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
- </if>
- <if test="vo.managementSource !=null and vo.managementSource!=''">
- and sd.management_source=#{vo.managementSource}
- </if>
- </where>
- group by pa.insurance_company, pa.partner_companies_id) a
- </select>
- <select id="channelAgentDetails" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
- SELECT
- iac.inscompany,
- COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS qutationCount,
- COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) AS underwritingCount,
- COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) AS qutationInsureCount,
- COUNT( CASE WHEN iot.order_status = '4' THEN 1 END ) AS underwritingReturn,
- COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) / COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS "passingRate",
- COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) / COUNT( CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "closeRate",
- (COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) + COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ))/ COUNT(
- CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "contributionRate",
- COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) / COUNT( CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "quotationRate",
- COUNT(CASE WHEN io.order_source = 0 and iot.order_status = '0' THEN 1 END) as "pcOrderSource",
- COUNT(CASE WHEN io.order_source = 1 and iot.order_status = '0' THEN 1 END) as "appOrderSource",
- COUNT( CASE WHEN iot.order_status = '1' THEN 1 END ) AS "auditOrder"
- FROM
- (
- select iot.suborder,iot.order_status from `ins_orders_track` iot
- GROUP BY iot.suborder ,iot.order_status
- ) iot
- left join ins_area_company iac ON iac.id = iot.suborder
- LEFT JOIN ins_orders io ON io.orderno = iac.orderno
- LEFT JOIN sys_dept sd ON sd.id = io.deptid
- <where>
- 1=1
- <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
- and io.deptid like "${taskStatisticsVo.provinceId}%"
- </if>
- <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
- and io.deptid like "${taskStatisticsVo.cityId}%"
- </if>
- <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
- and io.deptid like "${taskStatisticsVo.countyId}%"
- </if>
- <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
- and io.deptid like "${taskStatisticsVo.houseId}%"
- </if>
- <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
- and io.userid =#{taskStatisticsVo.userId}
- </if>
- <if test="taskStatisticsVo.managementSource != null and taskStatisticsVo.managementSource != ''">
- and sd.management_source =#{taskStatisticsVo.managementSource}
- </if>
- <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
- AND DATE_FORMAT( ica.signing_time, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND
- #{taskStatisticsVo.createtimeEnd}
- </if>
- <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
- AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate},
- '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
- </if>
- </where>
- GROUP BY
- iac.inscompany
- </select>
- </mapper>
|