Parcourir la source

员工效率分析

yzc il y a 1 an
Parent
commit
97c3d68fcf

+ 37 - 0
hx-from/src/main/java/com/fjhx/from/controller/EmployeeProductivityController.java

@@ -0,0 +1,37 @@
+package com.fjhx.from.controller;
+
+import com.fjhx.from.entity.EmployeeProductivity;
+import com.fjhx.from.service.EmployeeProductivityService;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+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.List;
+
+@RestController
+@RequestMapping("/employeeProductivity")
+public class EmployeeProductivityController {
+
+    @Autowired
+    private EmployeeProductivityService employeeProductivityService;
+
+    /**
+     * 员工效率分析
+     */
+    @PostMapping("/list")
+    public List<EmployeeProductivity> list(@RequestBody BaseSelectDto dto) {
+        return employeeProductivityService.getList(dto);
+    }
+
+    /**
+     * 员工效率分析列表统计
+     */
+    @PostMapping("/listStatistics")
+    public EmployeeProductivity listStatistics(@RequestBody BaseSelectDto dto) {
+        return employeeProductivityService.getListStatistics(dto);
+    }
+
+}

+ 11 - 0
hx-from/src/main/java/com/fjhx/from/entity/EmailCount.java

@@ -0,0 +1,11 @@
+package com.fjhx.from.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class EmailCount {
+    private Integer count;
+    private Long userId;
+}

+ 75 - 0
hx-from/src/main/java/com/fjhx/from/entity/EmployeeProductivity.java

@@ -0,0 +1,75 @@
+package com.fjhx.from.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class EmployeeProductivity {
+    /**
+     * 用户id
+     */
+    private Long userId;
+    /**
+     * 用户名
+     */
+    private String userName;
+    /**
+     * 邮件发送数
+     */
+    private Integer sendEmailCount;
+    /**
+     * 邮件接收数
+     */
+    private Integer receiveEmailCount;
+    /**
+     * 制作报价单数
+     */
+    private Integer quotationCount;
+    /**
+     * 新客户数
+     */
+    private Integer newCustomerCount;
+    /**
+     * 样品单客户数
+     */
+    private Integer sampleCustomerCount;
+    /**
+     * 新成交客户数
+     */
+    private Integer newDealCustomerCount;
+    /**
+     * 订单客户数
+     */
+    private Integer contractCustomerCount;
+    /**
+     * 名下客户数
+     */
+    private Integer customerCount;
+    /**
+     * 样品单数
+     */
+    private Integer sampleCount;
+    /**
+     * 新客户成单数
+     */
+    private Integer newCustomerContractCount;
+    /**
+     * 新客户成单金额
+     */
+    private BigDecimal newCustomerContractCnyAmount;
+    /**
+     * 老客户成单数
+     */
+    private Integer oldCustomerContractCount;
+    /**
+     * 老客户成单金额
+     */
+    private BigDecimal oldCustomerContractCnyAmount;
+    /**
+     * 订单总计
+     */
+    private Integer contractCount;
+}

+ 18 - 0
hx-from/src/main/java/com/fjhx/from/mapper/EmployeeProductivityMapper.java

@@ -0,0 +1,18 @@
+package com.fjhx.from.mapper;
+
+import com.fjhx.from.entity.EmailCount;
+import com.fjhx.from.entity.EmployeeProductivity;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface EmployeeProductivityMapper {
+
+    List<EmployeeProductivity> getList(@Param("ew") IWrapper<Object> wrapper, @Param("dto") BaseSelectDto dto);
+
+    List<EmailCount> getUserEmailCount(@Param("ew") IWrapper<Object> wrapper);
+}

+ 14 - 0
hx-from/src/main/java/com/fjhx/from/service/EmployeeProductivityService.java

@@ -0,0 +1,14 @@
+package com.fjhx.from.service;
+
+import com.fjhx.from.entity.EmployeeProductivity;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+
+import java.util.List;
+
+public interface EmployeeProductivityService {
+
+
+    List<EmployeeProductivity> getList(BaseSelectDto dto);
+
+    EmployeeProductivity getListStatistics(BaseSelectDto dto);
+}

+ 127 - 0
hx-from/src/main/java/com/fjhx/from/service/impl/EmployeeProductivityServiceImpl.java

@@ -0,0 +1,127 @@
+package com.fjhx.from.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
+import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.customer.service.customer.CustomerService;
+import com.fjhx.from.entity.EmailCount;
+import com.fjhx.from.entity.EmployeeProductivity;
+import com.fjhx.from.mapper.EmployeeProductivityMapper;
+import com.fjhx.from.service.EmployeeProductivityService;
+import com.fjhx.sale.service.contract.ContractService;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+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.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+public class EmployeeProductivityServiceImpl implements EmployeeProductivityService {
+
+    @Autowired
+    private EmployeeProductivityMapper employeeProductivityMapper;
+    @Autowired
+    private CustomerService customerService;
+    @Autowired
+    private ContractService contractService;
+
+    @Override
+    public List<EmployeeProductivity> getList(BaseSelectDto dto) {
+        //获取业务员列表
+        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+        List<EmployeeProductivity> salesmanList = employeeProductivityMapper.getList(IWrapper.getWrapper()
+                .eq("sr.role_key", "salesman"), dto
+        );
+        DynamicDataSourceContextHolder.poll();
+        if (ObjectUtil.isEmpty(salesmanList)) {
+            return salesmanList;
+        }
+        List<Long> userIds = salesmanList.stream().map(EmployeeProductivity::getUserId).collect(Collectors.toList());
+
+        //获取收邮件数列表
+        DynamicDataSourceContextHolder.push(SourceConstant.MAIL);
+        List<EmailCount> receiveEmailCount = employeeProductivityMapper.getUserEmailCount(IWrapper.getWrapper()
+                .in("t1.user_id", userIds)
+                .ge("t1.send_date", dto.getBeginTime())
+                .le("t1.send_date", dto.getEndTime())
+                .apply("t1.from_email != t1.mail_user"));
+        //获取发邮件数列表
+        List<EmailCount> sendEmailCount = employeeProductivityMapper.getUserEmailCount(IWrapper.getWrapper()
+                .in("t1.user_id", userIds)
+                .ge("t1.send_date", dto.getBeginTime())
+                .le("t1.send_date", dto.getEndTime())
+                .apply("t1.from_email = t1.mail_user"));
+        DynamicDataSourceContextHolder.poll();
+
+        Map<Long, Integer> receiveEmailCountMap = receiveEmailCount.stream().collect(Collectors.toMap(EmailCount::getUserId, EmailCount::getCount));
+        Map<Long, Integer> sendEmailCountMap = sendEmailCount.stream().collect(Collectors.toMap(EmailCount::getUserId, EmailCount::getCount));
+
+        //赋值数据
+        for (EmployeeProductivity employeeProductivity : salesmanList) {
+            Long userId = employeeProductivity.getUserId();
+            //赋值发件数
+            employeeProductivity.setSendEmailCount(sendEmailCountMap.getOrDefault(userId, 0));
+            //赋值收件数
+            employeeProductivity.setReceiveEmailCount(receiveEmailCountMap.getOrDefault(userId, 0));
+        }
+        return salesmanList;
+    }
+
+    @Override
+    public EmployeeProductivity getListStatistics(BaseSelectDto dto) {
+        Integer sendEmailCount = 0;
+        Integer receiveEmailCount = 0;
+        Integer quotationCount = 0;
+        Integer newCustomerCount = 0;
+        Integer sampleCustomerCount = 0;
+        Integer newDealCustomerCount = 0;
+        Integer contractCustomerCount = 0;
+        Integer customerCount = 0;
+        Integer sampleCount = 0;
+        Integer newCustomerContractCount = 0;
+        BigDecimal newCustomerContractCnyAmount = BigDecimal.ZERO;
+        Integer oldCustomerContractCount = 0;
+        BigDecimal oldCustomerContractCnyAmount = BigDecimal.ZERO;
+        Integer contractCount = 0;
+        List<EmployeeProductivity> list = getList(dto);
+        for (EmployeeProductivity employeeProductivity : list) {
+            sendEmailCount += employeeProductivity.getSendEmailCount();
+            receiveEmailCount += employeeProductivity.getReceiveEmailCount();
+            quotationCount += employeeProductivity.getQuotationCount();
+            newCustomerCount += employeeProductivity.getNewCustomerCount();
+            sampleCustomerCount += employeeProductivity.getSampleCustomerCount();
+            newDealCustomerCount += employeeProductivity.getNewDealCustomerCount();
+            contractCustomerCount += employeeProductivity.getContractCustomerCount();
+            customerCount += employeeProductivity.getCustomerCount();
+            sampleCount += employeeProductivity.getSampleCount();
+            newCustomerContractCount += employeeProductivity.getNewCustomerContractCount();
+            newCustomerContractCnyAmount = newCustomerContractCnyAmount.add(employeeProductivity.getNewCustomerContractCnyAmount());
+            oldCustomerContractCount += employeeProductivity.getOldCustomerContractCount();
+            oldCustomerContractCnyAmount = oldCustomerContractCnyAmount.add(employeeProductivity.getOldCustomerContractCnyAmount());
+            contractCount += employeeProductivity.getContractCount();
+        }
+
+        EmployeeProductivity reData = new EmployeeProductivity();
+        reData.setSendEmailCount(sendEmailCount);
+        reData.setReceiveEmailCount(receiveEmailCount);
+        reData.setQuotationCount(quotationCount);
+        reData.setNewCustomerCount(newCustomerCount);
+        reData.setSampleCustomerCount(sampleCustomerCount);
+        reData.setNewDealCustomerCount(newDealCustomerCount);
+        reData.setContractCustomerCount(contractCustomerCount);
+        reData.setCustomerCount(customerCount);
+        reData.setSampleCount(sampleCount);
+        reData.setNewCustomerContractCount(newCustomerContractCount);
+        reData.setNewCustomerContractCnyAmount(newCustomerContractCnyAmount);
+        reData.setOldCustomerContractCount(oldCustomerContractCount);
+        reData.setOldCustomerContractCnyAmount(oldCustomerContractCnyAmount);
+        reData.setContractCount(contractCount);
+
+        return reData;
+    }
+
+}

+ 210 - 0
hx-from/src/main/resources/mapper/EmployeeProductivityMapperMapper.xml

@@ -0,0 +1,210 @@
+<?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.from.mapper.EmployeeProductivityMapper">
+
+    <select id="getList" resultType="com.fjhx.from.entity.EmployeeProductivity">
+        SELECT
+        su.user_id,
+        su.nick_name as userName,
+        ( SELECT
+        count( 1 )
+        FROM
+        bytesailing_sale.sale_quotation sq
+        WHERE create_user = su.user_id
+        <if test="dto.beginTime != null">
+            AND create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND create_time &lt;= #{dto.endTime}
+        </if>
+        ) AS quotationCount,
+        ( SELECT
+        count( 1 )
+        FROM
+        bytesailing_customer.customer
+        WHERE create_user = su.user_id
+        <if test="dto.beginTime != null">
+            AND create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND create_time &lt;= #{dto.endTime}
+        </if>
+        ) AS newCustomerCount,
+        ( SELECT
+        COUNT( buy_corporation_id )
+        FROM
+        bytesailing_sale.sample
+        WHERE create_user = su.user_id
+        <if test="dto.beginTime != null">
+            AND create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND create_time &lt;= #{dto.endTime}
+        </if>
+        ) AS sampleCustomerCount,
+        (
+        SELECT
+        count( c.buy_corporation_id )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        c.buy_corporation_id IN ( SELECT c.id FROM bytesailing_customer.customer c WHERE c.user_id = su.user_id
+        <if test="dto.beginTime != null">AND c.create_time >= #{dto.beginTime}</if>
+        <if test="dto.endTime != null">AND c.create_time &lt;= #{dto.endTime}</if>
+        )
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag=0
+        ) AS newDealCustomerCount,
+        (
+        SELECT
+        count( c.buy_corporation_id )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        c.create_user = su.user_id
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) as contractCustomerCount,
+        ( SELECT count( 1 ) FROM bytesailing_customer.customer WHERE user_id = su.user_id AND del_flag = 0 ) AS
+        customerCount,
+        ( SELECT
+        count( 1 )
+        FROM bytesailing_sale.sample
+        WHERE create_user = su.user_id
+        <if test="dto.beginTime != null">
+            AND create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND create_time &lt;= #{dto.endTime}
+        </if>
+        AND del_flag = 0
+        ) AS sampleCount,
+        (
+        SELECT
+        count( 1 )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        c.buy_corporation_id IN ( SELECT c.id FROM bytesailing_customer.customer c WHERE c.user_id = su.user_id
+        <if test="dto.beginTime != null">AND c.create_time >= #{dto.beginTime}</if>
+        <if test="dto.endTime != null">AND c.create_time &lt;= #{dto.endTime}</if>
+        )
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) AS newCustomerContractCount,
+        (
+        SELECT
+        IFNULL( sum( c.amount * c.rate ), 0 )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        c.buy_corporation_id IN ( SELECT c.id FROM bytesailing_customer.customer c WHERE c.user_id = su.user_id
+        <if test="dto.beginTime != null">AND c.create_time >= #{dto.beginTime}</if>
+        <if test="dto.endTime != null">AND c.create_time &lt;= #{dto.endTime}</if>
+        )
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) AS newCustomerContractCnyAmount,
+        (
+        SELECT
+        count( 1 )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        NOT c.buy_corporation_id IN ( SELECT c.id FROM bytesailing_customer.customer c WHERE c.user_id = su.user_id
+        <if test="dto.beginTime != null">AND c.create_time >= #{dto.beginTime}</if>
+        <if test="dto.endTime != null">AND c.create_time &lt;= #{dto.endTime}</if>
+        )
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) AS oldCustomerContractCount,
+        (
+        SELECT
+        IFNULL( sum( c.amount * c.rate ), 0 )
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        NOT c.buy_corporation_id IN ( SELECT c.id FROM bytesailing_customer.customer c WHERE c.user_id = su.user_id
+        <if test="dto.beginTime != null">AND c.create_time >= #{dto.beginTime}</if>
+        <if test="dto.endTime != null">AND c.create_time &lt;= #{dto.endTime}</if>
+        )
+        <if test="dto.beginTime != null">
+            AND c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) AS oldCustomerContractCnyAmount,
+        (
+        SELECT
+        count(1)
+        FROM
+        bytesailing_sale.contract c
+        WHERE
+        <if test="dto.beginTime != null">
+            c.create_time >= #{dto.beginTime}
+        </if>
+        <if test="dto.endTime != null">
+            AND c.create_time &lt;= #{dto.endTime}
+        </if>
+        AND NOT c.`status` IN ( 0, 70, 88 )
+        AND c.del_flag = 0
+        ) AS contractCount
+        FROM
+        sys_user su
+        JOIN sys_user_role sur ON sur.user_id = su.user_id
+        JOIN sys_role sr ON sr.role_id = sur.role_id
+        ${ew.customSqlSegment}
+    </select>
+    <select id="getUserEmailCount" resultType="com.fjhx.from.entity.EmailCount">
+        SELECT count(1) count,
+	t1.user_id
+        FROM
+            (
+            SELECT
+            em.id, em.send_date, em.from_email, emb.user_id, CONCAT( emb.mail_user_prefix, '@', ed.domain_name ) AS mail_user
+            FROM
+            enterprise_message em
+            JOIN enterprise_mailbox emb ON em.mailbox_id = emb.id
+            JOIN enterprise_domain ed ON emb.domain_id = ed.id UNION ALL
+            SELECT
+            pm.id, pm.send_date, pm.from_email, pmb.user_id, pmb.mail_user
+            FROM
+            personal_message pm
+            JOIN personal_mailbox pmb ON pm.mailbox_id = pmb.id
+            ) t1
+            ${ew.customSqlSegment}
+    </select>
+</mapper>