|
@@ -42,4 +42,88 @@
|
|
id = ( SELECT personal_id FROM personal_target WHERE id = #{targetId} AND deleted = 0 ))
|
|
id = ( SELECT personal_id FROM personal_target WHERE id = #{targetId} AND deleted = 0 ))
|
|
and terminal = 0 and company_type = '银行及金融机构' and parent_id is null
|
|
and terminal = 0 and company_type = '银行及金融机构' and parent_id is null
|
|
</select>
|
|
</select>
|
|
|
|
+
|
|
|
|
+ <sql id="customerCompanyQuerySql">
|
|
|
|
+ SELECT company.id AS companyId,
|
|
|
|
+ company.name AS companyName,
|
|
|
|
+ parent.id AS parentId,
|
|
|
|
+ parent.name AS parentCompany,
|
|
|
|
+ company.company_type AS companyType,
|
|
|
|
+ company.address AS address,
|
|
|
|
+ company.phone AS phone,
|
|
|
|
+ user.name AS clientManager,
|
|
|
|
+ company.terminal AS terminal,
|
|
|
|
+ ((SELECT COUNT(id)
|
|
|
|
+ FROM assets
|
|
|
|
+ WHERE assets.deleted = 0
|
|
|
|
+ AND assets.clientele_sub_id = company.id) +
|
|
|
|
+ (SELECT COUNT(id)
|
|
|
|
+ FROM major
|
|
|
|
+ WHERE major.deleted = 0
|
|
|
|
+ AND major.clientele_sub_id = company.id) +
|
|
|
|
+ (SELECT COUNT(id)
|
|
|
|
+ FROM personal
|
|
|
|
+ WHERE personal.deleted = 0
|
|
|
|
+ AND personal.clientele_sub_id = company.id)) AS orderVolume,
|
|
|
|
+ (COALESCE((SELECT SUM(order_fund.real_amount)
|
|
|
|
+ FROM assets
|
|
|
|
+ LEFT JOIN order_fund
|
|
|
|
+ ON order_fund.business_type = 'ASSET_BUSINESS' AND order_fund.deleted = 0 AND
|
|
|
|
+ business_id = assets.id
|
|
|
|
+ WHERE assets.deleted = 0
|
|
|
|
+ AND assets.clientele_sub_id = company.id), 0) +
|
|
|
|
+ COALESCE((SELECT SUM(order_fund.real_amount)
|
|
|
|
+ FROM major
|
|
|
|
+ LEFT JOIN order_fund
|
|
|
|
+ ON order_fund.business_type = 'MAJOR_BUSINESS' AND order_fund.deleted = 0 AND
|
|
|
|
+ business_id = major.id
|
|
|
|
+ WHERE major.deleted = 0
|
|
|
|
+ AND major.clientele_sub_id = company.id), 0) +
|
|
|
|
+ COALESCE((SELECT SUM(order_fund.real_amount)
|
|
|
|
+ FROM personal
|
|
|
|
+ LEFT JOIN order_fund
|
|
|
|
+ ON order_fund.business_type = 'PERSONAL_BUSINESS' AND order_fund.deleted = 0 AND
|
|
|
|
+ business_id = personal.id
|
|
|
|
+ WHERE personal.deleted = 0
|
|
|
|
+ AND personal.clientele_sub_id = company.id), 0)) AS estimatedRevenue,
|
|
|
|
+ company.created AS created
|
|
|
|
+ FROM customer_company AS company
|
|
|
|
+ LEFT JOIN customer_company AS parent ON parent.id = company.parent_id
|
|
|
|
+ LEFT JOIN user ON user.id = company.client_manager_id
|
|
|
|
+ WHERE (company.level = 1
|
|
|
|
+ OR (company.terminal = 1 AND company.level = 0))
|
|
|
|
+ <if test="dto != null">
|
|
|
|
+ <if test="dto.companyName != null">
|
|
|
|
+ AND company.name LIKE CONCAT('%',#{dto.companyName},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.parentCompany != null">
|
|
|
|
+ AND parent.name LIKE CONCAT('%',#{dto.parentCompany},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.companyType != null">
|
|
|
|
+ AND company.company_type = #{dto.companyType}
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.address != null">
|
|
|
|
+ AND company.address LIKE CONCAT('%',#{dto.address},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.phone != null">
|
|
|
|
+ AND company.phone LIKE CONCAT('%',#{dto.phone},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.clientManagerId != null">
|
|
|
|
+ AND company.client_manager_id = #{dto.clientManagerId}
|
|
|
|
+ </if>
|
|
|
|
+ <if test="dto.terminal != null">
|
|
|
|
+ AND company.terminal = #{dto.terminal}
|
|
|
|
+ </if>
|
|
|
|
+ </if>
|
|
|
|
+ </sql>
|
|
|
|
+
|
|
|
|
+ <!--分页查询企业客户列表-->
|
|
|
|
+ <select id="getCustomerCompanyPage" resultType="com.dayou.vo.CustomerCompanyVO">
|
|
|
|
+ <include refid="customerCompanyQuerySql" />
|
|
|
|
+ </select>
|
|
|
|
+
|
|
|
|
+ <!--分页查询企业客户列表-->
|
|
|
|
+ <select id="exportCustomerCompanyPage" resultType="com.dayou.vo.CustomerCompanyVO">
|
|
|
|
+ <include refid="customerCompanyQuerySql" />
|
|
|
|
+ </select>
|
|
</mapper>
|
|
</mapper>
|