1.1.64 销售合同仪表盘接口。

dev
yinq 3 weeks ago
parent 64ff1ef519
commit 01ec290297

@ -0,0 +1,35 @@
package org.dromara.oa.erp.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.oa.erp.domain.bo.SalesContractDashboardBo;
import org.dromara.oa.erp.domain.vo.SalesContractDashboardVo;
import org.dromara.oa.erp.service.ISalesContractDashboardService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* 访:/oa/erp/salesContractDashboard
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/salesContractDashboard")
public class SalesContractDashboardController extends BaseController {
private final ISalesContractDashboardService salesContractDashboardService;
/**
*
*/
@SaCheckPermission("oa/erp:salesContractDashboard:query")
@GetMapping("/data")
public R<SalesContractDashboardVo> getDashboardData(SalesContractDashboardBo bo) {
return R.ok(salesContractDashboardService.queryDashboard(bo));
}
}

@ -0,0 +1,20 @@
package org.dromara.oa.erp.domain.bo;
import lombok.Data;
/**
*
*/
@Data
public class SalesContractDashboardBo {
/**
* yyyy-MM-dd
*/
private String beginDate;
/**
* yyyy-MM-dd
*/
private String endDate;
}

@ -0,0 +1,47 @@
package org.dromara.oa.erp.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Data
public class SalesContractDashboardVo {
/** 成交总额 */
private BigDecimal totalTransactionAmount;
/** 本周新签合同额 */
private BigDecimal weeklyNewContractAmount;
/** 业务方向销售额占比 */
private List<SalesContractDashboardVo> businessDirectionRatios = new ArrayList<>();
/** 成交额客户分布 */
private List<SalesContractDashboardVo> customerTransactionDistribution = new ArrayList<>();
/** 销售合同额排行 */
private List<SalesContractDashboardVo> salesContractRanking = new ArrayList<>();
/** 业务方向名称 / 通用名称 */
private String name;
/** 业务方向金额 / 通用数值 */
private BigDecimal value;
/** 客户名称 */
private String customerName;
/** 客户成交额 */
private BigDecimal amount;
/** 销售人员名称 */
private String salespersonName;
/** 销售合同金额 */
private BigDecimal contractAmount;
}

@ -0,0 +1,27 @@
package org.dromara.oa.erp.mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.oa.erp.domain.vo.SalesContractDashboardVo;
import java.math.BigDecimal;
import java.util.List;
/**
* Mapper
*/
public interface SalesContractDashboardMapper {
BigDecimal selectTotalTransactionAmount(@Param("beginDate") String beginDate,
@Param("endDate") String endDate);
BigDecimal selectWeeklyNewContractAmount();
List<SalesContractDashboardVo> selectBusinessDirectionRatios(@Param("beginDate") String beginDate,
@Param("endDate") String endDate);
List<SalesContractDashboardVo> selectCustomerTransactionDistribution(@Param("beginDate") String beginDate,
@Param("endDate") String endDate);
List<SalesContractDashboardVo> selectSalesContractRanking(@Param("beginDate") String beginDate,
@Param("endDate") String endDate);
}

@ -0,0 +1,15 @@
package org.dromara.oa.erp.service;
import org.dromara.oa.erp.domain.bo.SalesContractDashboardBo;
import org.dromara.oa.erp.domain.vo.SalesContractDashboardVo;
/**
* Service
*/
public interface ISalesContractDashboardService {
/**
*
*/
SalesContractDashboardVo queryDashboard(SalesContractDashboardBo bo);
}

@ -66,11 +66,7 @@ import org.springframework.stereotype.Service;
import org.apache.dubbo.config.annotation.DubboReference;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.map.MapUtil;
@ -387,6 +383,9 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
contractPatch.setSignatureAppendix(bo.getOssId().trim());
// contractPatch.setContractDeptId(bo.getDeptId());
contractPatch.setContractStatus(OAStatusEnum.ACTIVATE.getStatus());
if (StringUtils.isNull(contractInfoVo.getContractDate())){
contractPatch.setContractDate(new Date());
}
}
contractInfoMapper.updateById(contractPatch);
}

@ -0,0 +1,68 @@
package org.dromara.oa.erp.service.impl;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.service.DictService;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.oa.erp.domain.bo.SalesContractDashboardBo;
import org.dromara.oa.erp.domain.vo.SalesContractDashboardVo;
import org.dromara.oa.erp.mapper.SalesContractDashboardMapper;
import org.dromara.oa.erp.service.ISalesContractDashboardService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
/**
* Service
*/
@RequiredArgsConstructor
@Service
public class SalesContractDashboardServiceImpl implements ISalesContractDashboardService {
private static final String BUSINESS_DIRECTION_DICT = "business_direction";
private final SalesContractDashboardMapper dashboardMapper;
private final DictService dictService;
@Override
public SalesContractDashboardVo queryDashboard(SalesContractDashboardBo bo) {
String beginDate = bo.getBeginDate();
String endDate = bo.getEndDate();
if (StringUtils.isBlank(beginDate) || StringUtils.isBlank(endDate)) {
int year = LocalDate.now().getYear();
beginDate = year + "-01-01";
endDate = year + "-12-31";
}
SalesContractDashboardVo dashboardVo = new SalesContractDashboardVo();
dashboardVo.setTotalTransactionAmount(defaultAmount(
dashboardMapper.selectTotalTransactionAmount(beginDate, endDate)));
dashboardVo.setWeeklyNewContractAmount(defaultAmount(
dashboardMapper.selectWeeklyNewContractAmount()));
List<SalesContractDashboardVo> directionRatios =
dashboardMapper.selectBusinessDirectionRatios(beginDate, endDate);
directionRatios.forEach(item -> item.setName(resolveBusinessDirectionName(item.getName())));
dashboardVo.setBusinessDirectionRatios(directionRatios);
dashboardVo.setCustomerTransactionDistribution(
dashboardMapper.selectCustomerTransactionDistribution(beginDate, endDate));
dashboardVo.setSalesContractRanking(
dashboardMapper.selectSalesContractRanking(beginDate, endDate));
return dashboardVo;
}
private BigDecimal defaultAmount(BigDecimal amount) {
return amount == null ? BigDecimal.ZERO : amount;
}
private String resolveBusinessDirectionName(String businessDirection) {
if (StringUtils.isBlank(businessDirection) || "unknown".equals(businessDirection)) {
return "未分类";
}
String label = dictService.getDictLabel(BUSINESS_DIRECTION_DICT, businessDirection);
return StringUtils.isNotBlank(label) ? label : businessDirection;
}
}

@ -0,0 +1,75 @@
<?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) &gt;= #{beginDate}
</if>
<if test="endDate != null and endDate != ''">
AND DATE(t.contract_date) &lt;= #{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 &gt; 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 &gt; 0
ORDER BY contractAmount ASC
</select>
</mapper>
Loading…
Cancel
Save