|
|
<?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="org.dromara.oa.erp.mapper.SalesContractDashboardMapper">
|
|
|
|
|
|
<!-- 仅统计已激活合同(contract_status = 5) -->
|
|
|
<sql id="activatedContractWhere">
|
|
|
t.del_flag = '0'
|
|
|
AND t.contract_status = '5'
|
|
|
AND t.contract_date IS NOT NULL
|
|
|
</sql>
|
|
|
|
|
|
<sql id="baseContractWhere">
|
|
|
<include refid="activatedContractWhere"/>
|
|
|
<if test="beginDate != null and beginDate != ''">
|
|
|
AND DATE(t.contract_date) >= #{beginDate}
|
|
|
</if>
|
|
|
<if test="endDate != null and endDate != ''">
|
|
|
AND DATE(t.contract_date) <= #{endDate}
|
|
|
</if>
|
|
|
</sql>
|
|
|
|
|
|
<select id="selectTotalTransactionAmount" resultType="java.math.BigDecimal">
|
|
|
SELECT COALESCE(SUM(t.total_price), 0)
|
|
|
FROM erp_contract_info t
|
|
|
WHERE
|
|
|
<include refid="baseContractWhere"/>
|
|
|
</select>
|
|
|
|
|
|
<select id="selectWeeklyNewContractAmount" resultType="java.math.BigDecimal">
|
|
|
SELECT COALESCE(SUM(t.total_price), 0)
|
|
|
FROM erp_contract_info t
|
|
|
WHERE
|
|
|
<include refid="activatedContractWhere"/>
|
|
|
AND YEARWEEK(t.contract_date, 1) = YEARWEEK(CURDATE(), 1)
|
|
|
</select>
|
|
|
|
|
|
<select id="selectBusinessDirectionRatios" resultType="org.dromara.oa.erp.domain.vo.SalesContractDashboardVo">
|
|
|
SELECT
|
|
|
COALESCE(NULLIF(t.business_direction, ''), 'unknown') AS name,
|
|
|
COALESCE(SUM(t.total_price), 0) AS value
|
|
|
FROM erp_contract_info t
|
|
|
WHERE
|
|
|
<include refid="baseContractWhere"/>
|
|
|
GROUP BY COALESCE(NULLIF(t.business_direction, ''), 'unknown')
|
|
|
ORDER BY value DESC
|
|
|
</select>
|
|
|
|
|
|
<select id="selectCustomerTransactionDistribution" resultType="org.dromara.oa.erp.domain.vo.SalesContractDashboardVo">
|
|
|
SELECT
|
|
|
COALESCE(cust.customer_name, '未知客户') AS customerName,
|
|
|
COALESCE(SUM(t.total_price), 0) AS amount
|
|
|
FROM erp_contract_info t
|
|
|
LEFT JOIN crm_customer_info cust ON t.one_customer_id = cust.customer_id AND cust.del_flag = '0'
|
|
|
WHERE
|
|
|
<include refid="baseContractWhere"/>
|
|
|
GROUP BY t.one_customer_id, cust.customer_name
|
|
|
HAVING amount > 0
|
|
|
ORDER BY amount ASC
|
|
|
</select>
|
|
|
|
|
|
<select id="selectSalesContractRanking" resultType="org.dromara.oa.erp.domain.vo.SalesContractDashboardVo">
|
|
|
SELECT
|
|
|
COALESCE(u.nick_name, '未知') AS salespersonName,
|
|
|
COALESCE(SUM(t.total_price), 0) AS contractAmount
|
|
|
FROM erp_contract_info t
|
|
|
LEFT JOIN sys_user u ON u.user_id = t.contract_manager_id
|
|
|
WHERE
|
|
|
<include refid="baseContractWhere"/>
|
|
|
GROUP BY t.contract_manager_id, u.nick_name
|
|
|
HAVING contractAmount > 0
|
|
|
ORDER BY contractAmount ASC
|
|
|
</select>
|
|
|
</mapper>
|