Răsfoiți Sursa

员工分析50%

yzc 1 an în urmă
părinte
comite
840a5f1c18

+ 5 - 0
hx-admin/pom.xml

@@ -95,6 +95,11 @@
         </dependency>
 
         <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-form</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>

+ 30 - 0
hx-form/pom.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.fjhx</groupId>
+        <artifactId>bytesailing</artifactId>
+        <version>1.0</version>
+    </parent>
+
+    <artifactId>hx-form</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-base</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-customer</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-sale</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 32 - 0
hx-form/src/main/java/com/fjhx/form/controller/employee/EmployeeAnalysisController.java

@@ -0,0 +1,32 @@
+package com.fjhx.form.controller.employee;
+
+import com.fjhx.form.entity.dto.EmployeeAnalysisDto;
+import com.fjhx.form.service.employee.EmployeeAnalysisService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * 员工分析 前端控制器
+ */
+@RestController
+@RequestMapping("/employeeAnalysis")
+public class EmployeeAnalysisController {
+
+    @Autowired
+    private EmployeeAnalysisService employeeAnalysisService;
+
+    /**
+     * 员工分析
+     *
+     * @return
+     */
+    @PostMapping("/info")
+    public Map<String, Object> info(@RequestBody EmployeeAnalysisDto dto) {
+        return employeeAnalysisService.info(dto);
+    }
+}

+ 30 - 0
hx-form/src/main/java/com/fjhx/form/entity/dto/EmployeeAnalysisDto.java

@@ -0,0 +1,30 @@
+package com.fjhx.form.entity.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * 客户分析dto
+ */
+@Getter
+@Setter
+public class EmployeeAnalysisDto {
+
+    /**
+     * 用户id列表
+     */
+    private List<Long> userIds;
+
+    /**
+     * 开始时间
+     */
+    private String beginTime;
+
+    /**
+     * 结束时间
+     */
+    private String endTime;
+
+}

+ 27 - 0
hx-form/src/main/java/com/fjhx/form/mapper/employee/EmployeeAnalysisMapper.java

@@ -0,0 +1,27 @@
+package com.fjhx.form.mapper.employee;
+
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+@Mapper
+public interface EmployeeAnalysisMapper {
+
+    /**
+     * 获取邮件信息
+     */
+    BigDecimal getMail(@Param("ew") IWrapper<Object> wrapper);
+
+    /**
+     * 获取报价单统计
+     */
+    Map<String, Object> getQuotationStatistics(@Param("ew") IWrapper<Object> wrapper);
+
+    /**
+     * 获取销售合同统计
+     */
+    Map<String, Object> getContractStatistics(@Param("ew") IWrapper<Object> wrapper);
+}

+ 10 - 0
hx-form/src/main/java/com/fjhx/form/service/employee/EmployeeAnalysisService.java

@@ -0,0 +1,10 @@
+package com.fjhx.form.service.employee;
+
+import com.fjhx.form.entity.dto.EmployeeAnalysisDto;
+
+import java.util.Map;
+
+public interface EmployeeAnalysisService {
+
+    Map<String, Object> info(EmployeeAnalysisDto dto);
+}

+ 200 - 0
hx-form/src/main/java/com/fjhx/form/service/employee/impl/EmployeeAnalysisServiceImpl.java

@@ -0,0 +1,200 @@
+package com.fjhx.form.service.employee.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
+import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.customer.entity.customer.po.Customer;
+import com.fjhx.customer.service.customer.CustomerService;
+import com.fjhx.flow.entity.flow.po.FlowExample;
+import com.fjhx.flow.service.flow.FlowExampleService;
+import com.fjhx.form.entity.dto.EmployeeAnalysisDto;
+import com.fjhx.form.mapper.employee.EmployeeAnalysisMapper;
+import com.fjhx.form.service.employee.EmployeeAnalysisService;
+import com.fjhx.item.entity.product.po.ProductInfo;
+import com.fjhx.item.service.product.ProductInfoService;
+import com.fjhx.sale.entity.contract.po.Contract;
+import com.fjhx.sale.entity.sale.po.SaleQuotation;
+import com.fjhx.sale.service.contract.ContractService;
+import com.fjhx.sale.service.sale.SaleQuotationService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class EmployeeAnalysisServiceImpl implements EmployeeAnalysisService {
+
+    @Autowired
+    private CustomerService customerService;
+    @Autowired
+    private SaleQuotationService saleQuotationService;
+    @Autowired
+    private ContractService contractService;
+    @Autowired
+    private ProductInfoService productInfoService;
+    @Autowired
+    private EmployeeAnalysisMapper employeeAnalysisMapper;
+    @Autowired
+    private FlowExampleService flowExampleService;
+
+    /**
+     * 员工分析
+     *
+     * @return
+     */
+    @Override
+    public Map<String, Object> info(EmployeeAnalysisDto dto) {
+        //客户情况
+        Map<String, Object> customerSituation = getCustomerSituation(dto);
+        //产品情况
+        Map<String, Object> productSituation = getProductSituation(dto);
+        //往来邮件
+        Map<String, Object> commEmail = getCommEmail(dto);
+        //流程统计
+        Map<String, Object> flowStatistics = getFlowStatistics(dto);
+
+
+        /**
+         * 销售行为(存量客户)
+         */
+
+
+        /**
+         * 销售行为(增量客户)
+         */
+        Map<String, Object> saleAddSituation = new HashMap<>();
+        //报价统计(报价单)
+        DynamicDataSourceContextHolder.push(SourceConstant.SALE);
+        Map<String, Object> quotationAddStatistics = employeeAnalysisMapper.getQuotationStatistics(IWrapper.getWrapper()
+                .eq("status", 30)
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), "sq.create_time", dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), "sq.create_time", dto.getEndTime())
+        );
+        //成交统计(销售合同)
+        Map<String, Object> contractAddStatistics = employeeAnalysisMapper.getContractStatistics(IWrapper.getWrapper()
+                .eq("status", 30)
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), "c.create_time", dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), "c.create_time", dto.getEndTime())
+        );
+        DynamicDataSourceContextHolder.poll();
+        saleAddSituation.put("quotationAddStatistics", quotationAddStatistics);
+        saleAddSituation.put("contractAddStatistics", contractAddStatistics);
+
+
+        //返回数据
+        Map<String, Object> data = new HashMap<>();
+        data.put("customerSituation", customerSituation);//客户情况
+        data.put("productSituation", productSituation);//产品情况
+        data.put("commMail", commEmail);//往来邮件
+        data.put("flowStatistics", flowStatistics);//流程统计
+        data.put("saleAddSituation", saleAddSituation);//销售行为新增统计
+        return data;
+    }
+
+    /**
+     * 客户情况
+     */
+    private Map<String, Object> getCustomerSituation(EmployeeAnalysisDto dto) {
+        Map<String, Object> customerSituation = new HashMap<>();
+        //客户存量
+        long customerCount = customerService.count(q -> q
+                .lt(ObjectUtil.isNotEmpty(dto.getBeginTime()), Customer::getCreateTime, dto.getBeginTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), Customer::getUserId, dto.getUserIds())
+        );
+        //客户新增
+        long customerAddCount = customerService.count(q -> q
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), Customer::getCreateTime, dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), Customer::getCreateTime, dto.getEndTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), Customer::getCreateUser, dto.getUserIds())
+        );
+        //报价单(客户数量)
+        List<SaleQuotation> saleQuotationList = saleQuotationService.list(q -> q
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), SaleQuotation::getCreateTime, dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), SaleQuotation::getCreateTime, dto.getEndTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), SaleQuotation::getCreateUser, dto.getUserIds())
+                .groupBy(SaleQuotation::getBuyCorporationId)
+        );
+        int saleQuotationCustomerCount = saleQuotationList.size();
+        //成交合同(客户数量)
+        List<Contract> contractList = contractService.list(q -> q
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), Contract::getCreateTime, dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), Contract::getCreateTime, dto.getEndTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), Contract::getCreateUser, dto.getUserIds())
+                .groupBy(Contract::getBuyCorporationId)
+        );
+        int contractCustomerCount = contractList.size();
+        customerSituation.put("customerCount", customerCount);
+        customerSituation.put("customerAddCount", customerAddCount);
+        customerSituation.put("saleQuotationCustomerCount", saleQuotationCustomerCount);
+        customerSituation.put("contractCustomerCount", contractCustomerCount);
+        return customerSituation;
+    }
+
+    /**
+     * 产品情况
+     */
+    private Map<String, Object> getProductSituation(EmployeeAnalysisDto dto) {
+        Map<String, Object> productSituation = new HashMap<>();
+        //产品存量
+        long productCount = productInfoService.count(q -> q
+                .lt(ObjectUtil.isNotEmpty(dto.getBeginTime()), ProductInfo::getCreateTime, dto.getBeginTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), ProductInfo::getCreateUser, dto.getUserIds())
+        );
+        //产品添加
+        long productAddCount = productInfoService.count(q -> q
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), ProductInfo::getCreateTime, dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), ProductInfo::getCreateTime, dto.getEndTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), ProductInfo::getCreateUser, dto.getUserIds())
+        );
+        productSituation.put("productCount", productCount);
+        productSituation.put("productAddCount", productAddCount);
+        return productSituation;
+    }
+
+    /**
+     * 往来邮件
+     */
+    private Map<String, Object> getCommEmail(EmployeeAnalysisDto dto) {
+        Map<String, Object> commEmail = new HashMap<>();
+        DynamicDataSourceContextHolder.push(SourceConstant.MAIL);
+        //获取发件数
+        BigDecimal sentMailCount = employeeAnalysisMapper.getMail(IWrapper.getWrapper()
+                .eq("t1.folder_name", "Sent Messages")
+                .in("t2.user_id", dto.getUserIds())
+        );
+        //获取收件数
+        BigDecimal receiveMailCount = employeeAnalysisMapper.getMail(IWrapper.getWrapper()
+                .ne("t1.folder_name", "Sent Messages")
+                .in("t2.user_id", dto.getUserIds())
+        );
+        DynamicDataSourceContextHolder.poll();
+        commEmail.put("sentMailCount", sentMailCount);
+        commEmail.put("receiveMailCount", receiveMailCount);
+        return commEmail;
+    }
+
+    /**
+     * 流程统计
+     */
+    private Map<String, Object> getFlowStatistics(EmployeeAnalysisDto dto) {
+        Map<String, Object> flowStatistics = new HashMap<>();
+        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+        long flowExampleCount = flowExampleService.count(q -> q
+                .ge(ObjectUtil.isNotEmpty(dto.getBeginTime()), FlowExample::getCreateTime, dto.getBeginTime())
+                .le(ObjectUtil.isNotEmpty(dto.getEndTime()), FlowExample::getCreateTime, dto.getEndTime())
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), FlowExample::getCreateUser, dto.getUserIds())
+        );
+        long waitFlowExampleCount = flowExampleService.count(q -> q
+                .in(ObjectUtil.isNotEmpty(dto.getUserIds()), FlowExample::getHandleUserId, dto.getUserIds())
+                .eq(FlowExample::getStatus, 1)
+        );
+        DynamicDataSourceContextHolder.poll();
+        flowStatistics.put("flowExampleCount", flowExampleCount);
+        flowStatistics.put("waitFlowExampleCount", waitFlowExampleCount);
+        return flowStatistics;
+    }
+}

+ 33 - 0
hx-form/src/main/resources/mapper/EmployeeAnalysisMapper.xml

@@ -0,0 +1,33 @@
+<?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.fjhx.form.mapper.employee.EmployeeAnalysisMapper">
+
+    <select id="getMail" resultType="java.math.BigDecimal">
+        SELECT sum(a.count)
+        FROM (SELECT count(1) AS `count`
+              FROM enterprise_message t1
+                       JOIN enterprise_mailbox t2
+                            ON t1.mailbox_id = t2.id
+                  ${ew.customSqlSegment}
+              UNION
+              SELECT
+                  count ( 1 ) AS `count`
+              FROM
+                  personal_message t1
+                  JOIN personal_mailbox t2
+              ON t1.mailbox_id = t2.id
+                  ${ew.customSqlSegment}) AS a
+    </select>
+    <select id="getQuotationStatistics" resultType="java.util.Map">
+        SELECT if(count(1) is null, 0, count(1))                                 AS `count`,
+               if(sum(sq.amount * sq.rate) is null, 0, sum(sq.amount * sq.rate)) AS sumAmount
+        FROM sale_quotation sq
+            ${ew.customSqlSegment}
+    </select>
+    <select id="getContractStatistics" resultType="java.util.Map">
+        SELECT if(count(1) is null, 0, count(1))                             AS `count`,
+               if(sum(c.amount * c.rate) is null, 0, sum(c.amount * c.rate)) AS sumAmount
+        FROM contract c
+            ${ew.customSqlSegment}
+    </select>
+</mapper>

+ 7 - 0
pom.xml

@@ -31,6 +31,7 @@
         <module>hx-dingding</module>
         <module>hx-data</module>
         <module>hx-jxst</module>
+        <module>hx-form</module>
     </modules>
 
     <properties>
@@ -163,6 +164,12 @@
                 <version>${hx.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>com.fjhx</groupId>
+                <artifactId>hx-form</artifactId>
+                <version>${hx.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>