Bladeren bron

迁移统计

yfh 1 week geleden
bovenliggende
commit
25aefa9ad5

+ 54 - 0
fs-admin/src/main/java/com/fs/crm/controller/ReportController.java

@@ -0,0 +1,54 @@
+package com.fs.crm.controller;
+
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.model.LoginUser;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.utils.ServletUtils;
+import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.crm.domain.Report;
+import com.fs.framework.web.service.TokenService;
+import com.fs.crm.param.ReportParam;
+import com.fs.crm.service.ReportService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+@RestController
+@RequestMapping("/crm/report")
+public class ReportController extends BaseController {
+    @Autowired
+    private ReportService reportService;
+    @Autowired
+    private TokenService tokenService;
+    @GetMapping("/reportList")
+    public TableDataInfo getReport(ReportParam param, HttpServletRequest request)
+    {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+
+        Long userId = loginUser.getUser().getUserId();
+        param.setCompanyUserId(userId);
+        List<Report> list = reportService.getReport(param);
+        return getDataTable(list);
+    }
+    @GetMapping("/export")
+    public AjaxResult export(ReportParam param,HttpServletRequest request)
+    {
+        LoginUser loginUser = tokenService.getLoginUser(request);
+
+        Long userId = loginUser.getUser().getUserId();
+        param.setCompanyUserId(userId);
+        List<Report> list = reportService.getReport(param);
+        if (CollectionUtils.isEmpty(list)){
+            return AjaxResult.error("请选择导出数据");
+        }
+        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
+        return util.exportExcel(list, "report");
+    }
+
+}

+ 62 - 0
fs-admin/src/main/java/com/fs/stats/FsStatsMemberController.java

@@ -0,0 +1,62 @@
+package com.fs.stats;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.statis.service.IFsStatsMemberDailyService;
+import com.fs.statis.vo.FsStatsMemberDailyVO;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/stats/member")
+@AllArgsConstructor
+public class FsStatsMemberController {
+
+    private final IFsStatsMemberDailyService statsMemberDailyService;
+
+    @GetMapping("/dailyData")
+    public AjaxResult dailyData(@RequestParam String startDate,
+                                @RequestParam String endDate,
+                                @RequestParam Integer type,
+                                @RequestParam(required = false) Long companyId,
+                                @RequestParam(required = false) Long companyUserId,
+                                @RequestParam(required = false) Long userId,
+                                @RequestParam(required = false) String phone,
+                                @RequestParam(required = false) Long trainCampId,
+                                @RequestParam(required = false) Long periodId,
+                                @RequestParam(required = false) Long courseId,
+                                @RequestParam(required = false) Long videoId,
+                                @RequestParam(required = false, defaultValue = "1") Integer pageNum,
+                                @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("companyId", companyId);
+        params.put("companyUserId", companyUserId);
+        params.put("userId", userId);
+        params.put("phone", phone);
+        params.put("trainCampId", trainCampId);
+        params.put("periodId", periodId);
+        params.put("courseId", courseId);
+        params.put("videoId", videoId);
+
+        if (type == 1) {
+            params.put("startDate", LocalDate.parse(startDate));
+            params.put("endDate", LocalDate.parse(endDate).plusDays(1));
+        } else {
+            params.put("startDate", LocalDate.parse(startDate).withDayOfMonth(1));
+            params.put("endDate", LocalDate.parse(endDate).withDayOfMonth(1).plusMonths(1));
+        }
+
+        PageHelper.startPage(pageNum, pageSize);
+        List<FsStatsMemberDailyVO> list = statsMemberDailyService.selectDailyData(params);
+        return AjaxResult.success(new PageInfo<>(list));
+    }
+}

+ 3 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -315,4 +315,7 @@ public interface CompanyUserMapper
 
     @Update("update company_user set doctor_id = null where user_id = #{userId}")
     public int unBindDoctorId(@Param("userId")Long userId);
+
+
+    List<String> selectCompanyUserNameByIdsList(@Param("companyUserIDs")List<Long> companyUserID);
 }

+ 38 - 0
fs-service/src/main/java/com/fs/crm/domain/CrmCustomerAssist.java

@@ -0,0 +1,38 @@
+package com.fs.crm.domain;
+
+import com.fs.common.annotation.Excel;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+
+/**
+ * 客户员工协作对象 crm_customer_assist
+ *
+ * @author fs
+ * @date 2025-05-27
+ */
+@Data
+public class CrmCustomerAssist extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** $column.columnComment */
+    private Long id;
+
+    /** $column.columnComment */
+    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
+    private Long companyId;
+
+    /** 销售ID */
+    @Excel(name = "销售ID")
+    private Long companyUserId;
+
+    /** 销售名字 */
+    @Excel(name = "销售名字")
+    private String companyUserName;
+
+    /** 销售公司ID */
+    @Excel(name = "销售公司ID")
+    private Long customerId;
+
+    private Integer Rate;
+}

+ 43 - 0
fs-service/src/main/java/com/fs/crm/domain/Report.java

@@ -0,0 +1,43 @@
+package com.fs.crm.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class Report {
+    //订单编号
+    @Excel(name = "订单编号")
+    private String orderSn;
+    //成单金额
+    @Excel(name = "成单金额")
+    private BigDecimal money;
+    //支付时间
+    @Excel(name = "支付时间" ,width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date payTime;
+    //订单状态
+    @Excel(name = "订单状态")
+    private String orderStatus;
+    //客户名称
+    @Excel(name = "客户名称")
+    private String userName;
+    //是否共享客户1是0否
+    @Excel(name = "是否共享客户")
+    private String status;
+    //共享销售
+    @Excel(name = "共享销售")
+    private String companyUserNames;
+    //分成比例
+    @Excel(name = "分成比例")
+    private BigDecimal proportion;
+    //我的业绩
+    @Excel(name = "我的业绩")
+    private BigDecimal myPerformance;
+    //客户id
+    @Excel(name = "客户id")
+    private Long customerId;
+}

+ 87 - 0
fs-service/src/main/java/com/fs/crm/mapper/CrmCustomerAssistMapper.java

@@ -0,0 +1,87 @@
+package com.fs.crm.mapper;
+
+import com.fs.crm.domain.CrmCustomerAssist;
+import com.fs.crm.param.CrmCustomerAssistDeLParam;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 客户员工协作Mapper接口
+ *
+ * @author fs
+ * @date 2025-05-27
+ */
+public interface CrmCustomerAssistMapper
+{
+    /**
+     * 查询客户员工协作
+     *
+     * @param id 客户员工协作ID
+     * @return 客户员工协作
+     */
+    public CrmCustomerAssist selectCrmCustomerAssistById(Long id);
+
+    /**
+     * 查询客户员工协作列表
+     *
+     * @param crmCustomerAssist 客户员工协作
+     * @return 客户员工协作集合
+     */
+    public List<CrmCustomerAssist> selectCrmCustomerAssistList(CrmCustomerAssist crmCustomerAssist);
+
+    /**
+     * 新增客户员工协作
+     *
+     * @param crmCustomerAssist 客户员工协作
+     * @return 结果
+     */
+    public int insertCrmCustomerAssist(CrmCustomerAssist crmCustomerAssist);
+
+    /**
+     * 修改客户员工协作
+     *
+     * @param crmCustomerAssist 客户员工协作
+     * @return 结果
+     */
+    public int updateCrmCustomerAssist(CrmCustomerAssist crmCustomerAssist);
+
+    /**
+     * 删除客户员工协作
+     *
+     * @param id 客户员工协作ID
+     * @return 结果
+     */
+    public int deleteCrmCustomerAssistById(Long id);
+
+    /**
+     * 批量删除客户员工协作
+     *
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+    public int deleteCrmCustomerAssistByIds(Long[] ids);
+
+    List<String> selectCompanyUserNameByCustomerId(@Param("customerId") Long customerId);
+
+    int removeByCustomer(@Param("maps") CrmCustomerAssistDeLParam param);
+
+    int deleteCrmCustomerAssistByCustomerId(Long customerId);
+
+    /**
+     * 查询当前销售协作的客户
+     * @param companyUserId
+     * @return
+     */
+    List<Long> selectCustomerIdByCompanyUserId(@Param("companyUserId") Long companyUserId);
+
+    /**
+     * 根据客户id查询销售
+     * @param customerId
+     * @return
+     */
+    List<Long> selectCompanyUserIdByCustomerId(@Param("customerId") Long customerId,@Param("createTime") Date createTime);
+
+    List<CrmCustomerAssist> selectByCustomerId(Long customerId);
+}

+ 7 - 0
fs-service/src/main/java/com/fs/crm/mapper/CrmCustomerMapper.java

@@ -959,4 +959,11 @@ public interface CrmCustomerMapper extends BaseMapper<CrmCustomer> {
 
     List<CrmMyCustomerListQueryVO> selectCrmMyAssistListQuery(@Param("maps") CrmMyCustomerListQueryParam param);
 
+    /**
+     * 查询当前销售的客户
+     * @param companyUserId
+     * @return
+     */
+    List<Long> selectCustomerIdByCompanyUserId(@Param("companyUserId") Long companyUserId);
+
 }

+ 11 - 0
fs-service/src/main/java/com/fs/crm/param/CrmCustomerAssistDeLParam.java

@@ -0,0 +1,11 @@
+package com.fs.crm.param;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CrmCustomerAssistDeLParam {
+    private List<Long> customerIds;
+    private Long companyUserId;
+}

+ 21 - 0
fs-service/src/main/java/com/fs/crm/param/ReportParam.java

@@ -0,0 +1,21 @@
+package com.fs.crm.param;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fs.common.param.BaseQueryParam;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class ReportParam extends BaseQueryParam {
+    private Long companyId;
+    private Long companyUserId;
+    private Double money;
+    private String rechargeNo;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date payTime;
+    private String status;
+    private String orderStatus;
+    private List<Long> customerIds;
+}

+ 11 - 0
fs-service/src/main/java/com/fs/crm/service/ReportService.java

@@ -0,0 +1,11 @@
+package com.fs.crm.service;
+
+
+import com.fs.crm.domain.Report;
+import com.fs.crm.param.ReportParam;
+
+import java.util.List;
+
+public interface ReportService {
+    List<Report> getReport(ReportParam param);
+}

+ 70 - 0
fs-service/src/main/java/com/fs/crm/service/impl/ReportServiceImpl.java

@@ -0,0 +1,70 @@
+package com.fs.crm.service.impl;
+
+import com.fs.company.mapper.CompanyUserMapper;
+import com.fs.crm.domain.Report;
+import com.fs.crm.mapper.CrmCustomerAssistMapper;
+import com.fs.crm.mapper.CrmCustomerMapper;
+import com.fs.crm.service.ReportService;
+import com.fs.his.mapper.FsStoreOrderMapper;
+import com.fs.crm.param.ReportParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Service
+public class ReportServiceImpl implements ReportService {
+    @Autowired
+    private CrmCustomerMapper crmCustomerMapper;
+    @Autowired
+    private CrmCustomerAssistMapper crmCustomerAssistMapper;
+    @Autowired
+    private FsStoreOrderMapper storeOrderMapper;
+    @Autowired
+    private CompanyUserMapper companyUserMapper;
+    @Override
+    public List<Report> getReport(ReportParam param) {
+        Set<Long> mergedSet = new HashSet<>();
+
+        if (param.getCompanyUserId()!=null){
+            //查询当前销售的客户以及协作客户
+            List<Long> customerIds = Optional.ofNullable(crmCustomerMapper.selectCustomerIdByCompanyUserId(param.getCompanyUserId()))
+                    .orElse(Collections.emptyList());
+            List<Long> assistCustomerIds = Optional.ofNullable(crmCustomerAssistMapper.selectCustomerIdByCompanyUserId(param.getCompanyUserId()))
+                    .orElse(Collections.emptyList());
+            mergedSet = Stream.concat(customerIds.stream(), assistCustomerIds.stream())
+                    .collect(Collectors.toSet());
+            mergedSet.addAll(customerIds);
+            mergedSet.addAll(assistCustomerIds);
+            if (mergedSet.isEmpty()){
+                return Collections.emptyList();
+            }
+            param.setCustomerIds(new ArrayList<>(mergedSet));
+        }
+        //查询客户的订单记录
+        List<Report> reports = storeOrderMapper.selectOrderByCustomerIds(param);
+        for (Report report : reports) {
+            //查询用户下单时是否共享客户,有哪些销售共享
+            List<Long> companyUserIds = crmCustomerAssistMapper.selectCompanyUserIdByCustomerId(report.getCustomerId(), report.getPayTime());
+            if (companyUserIds.size()>0){
+                report.setStatus("1");
+                String s = companyUserMapper.selectCompanyUserNameByIdsList(companyUserIds).toString();
+                String replace = s.replace("[", "");
+                String replace1 = replace.replace("]", "");
+                report.setCompanyUserNames(replace1);
+            }
+            //计算销售的业绩
+            //分成比例
+            BigDecimal bigDecimal = new BigDecimal("100.00");
+            BigDecimal ratio = bigDecimal.divide(new BigDecimal(companyUserIds.size()), 2, RoundingMode.HALF_UP);
+            report.setProportion(ratio);
+            report.setMyPerformance(ratio.multiply(report.getMoney()).divide(bigDecimal));
+            //修改对象
+        }
+        return reports;
+    }
+}

+ 5 - 0
fs-service/src/main/java/com/fs/his/mapper/FsStoreOrderMapper.java

@@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.fs.company.param.FsStoreStatisticsParam;
 import com.fs.company.vo.FsStoreOrderStatisticsVO;
 import com.fs.company.vo.FsStoreProductStatisticsVO;
+import com.fs.crm.domain.Report;
+import com.fs.crm.param.ReportParam;
 import com.fs.his.domain.FsInquiryOrderMsg;
 import com.fs.his.domain.FsStoreOrder;
 import com.fs.his.domain.FsStoreOrderItem;
@@ -1163,4 +1165,7 @@ public interface FsStoreOrderMapper
     Long selectFsStoreOrderListVOByErpAccountByExportCount(@Param("maps")FsStoreOrderParam param);
 
     List<FsStoreOrderErpExportVO> selectFsStoreOrderListErpVOByExport(@Param("maps")FsStoreOrderParam fsStoreOrder);
+
+
+    List<Report> selectOrderByCustomerIds(@Param("map") ReportParam param);
 }

+ 8 - 0
fs-service/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -565,4 +565,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{userId}
         </foreach>
     </update>
+
+    <select id="selectCompanyUserNameByIdsList" resultType="java.lang.String">
+        SELECT nick_name from company_user where user_id in
+        <foreach collection="companyUserIDs" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
+
 </mapper>

+ 108 - 0
fs-service/src/main/resources/mapper/crm/CrmCustomerAssistMapper.xml

@@ -0,0 +1,108 @@
+<?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.fs.crm.mapper.CrmCustomerAssistMapper">
+
+    <resultMap type="CrmCustomerAssist" id="CrmCustomerAssistResult">
+        <result property="id"    column="id"    />
+        <result property="companyId"    column="company_id"    />
+        <result property="companyUserId"    column="company_user_id"    />
+        <result property="companyUserName"    column="company_user_name"    />
+        <result property="customerId"    column="customer_id"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="rate"    column="rate"    />
+    </resultMap>
+
+    <sql id="selectCrmCustomerAssistVo">
+        select id, company_id, company_user_id,company_user_name, customer_id, create_time,rate from crm_customer_assist
+    </sql>
+
+    <select id="selectCrmCustomerAssistList" parameterType="CrmCustomerAssist" resultMap="CrmCustomerAssistResult">
+        <include refid="selectCrmCustomerAssistVo"/>
+        <where>
+            <if test="companyId != null "> and company_id = #{companyId}</if>
+            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
+            <if test="companyUserName != null and companyUserName != ''"> and company_user_name = #{companyUserName}</if>
+            <if test="customerId != null "> and customer_id = #{customerId}</if>
+        </where>
+    </select>
+
+    <select id="selectCrmCustomerAssistById" parameterType="Long" resultMap="CrmCustomerAssistResult">
+        <include refid="selectCrmCustomerAssistVo"/>
+        where id = #{id}
+    </select>
+    <select id="selectCompanyUserNameByCustomerId" resultType="java.lang.String">
+        select  CONCAT(company_user_name, '(', company_user_id, ')','分佣:',rate,'%') AS assistUser
+        from crm_customer_assist
+        where customer_id = #{customerId}
+    </select>
+    <select id="selectCustomerIdByCompanyUserId" resultType="java.lang.Long">
+        SELECT customer_id FROM crm_customer_assist where company_user_id = #{companyUserId}
+    </select>
+    <select id="selectCompanyUserIdByCustomerId" resultType="java.lang.Long">
+        select company_user_id from crm_customer_assist where customer_id = #{customerId} and create_time &lt; #{createTime}
+    </select>
+    <select id="selectByCustomerId" resultType="com.fs.crm.domain.CrmCustomerAssist">
+        <include refid="selectCrmCustomerAssistVo"/>
+        where  customer_id = #{customerId}
+
+    </select>
+
+    <insert id="insertCrmCustomerAssist" parameterType="CrmCustomerAssist" useGeneratedKeys="true" keyProperty="id">
+        insert into crm_customer_assist
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="companyId != null">company_id,</if>
+            <if test="companyUserId != null">company_user_id,</if>
+            <if test="companyUserName != null">company_user_name,</if>
+            <if test="customerId != null">customer_id,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="rate != null">rate,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="companyId != null">#{companyId},</if>
+            <if test="companyUserId != null">#{companyUserId},</if>
+            <if test="companyUserName != null">#{companyUserName},</if>
+            <if test="customerId != null">#{customerId},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="rate != null">#{rate},</if>
+         </trim>
+    </insert>
+
+    <update id="updateCrmCustomerAssist" parameterType="CrmCustomerAssist">
+        update crm_customer_assist
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="companyId != null">company_id = #{companyId},</if>
+            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
+            <if test="companyUserName != null">company_user_name = #{companyUserName},</if>
+            <if test="customerId != null">customer_id = #{customerId},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="rate != null">rate = #{rate},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteCrmCustomerAssistById" parameterType="Long">
+        delete from crm_customer_assist where id = #{id}
+    </delete>
+
+    <delete id="deleteCrmCustomerAssistByIds" parameterType="String">
+        delete from crm_customer_assist where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+    <delete id="removeByCustomer">
+        delete from crm_customer_assist where customer_id in
+        <foreach collection="maps.customerIds" item="customerId" open="(" separator="," close=")">
+            #{customerId}
+        </foreach>
+        <if test="maps.companyUserId != null">
+            and company_user_id = #{maps.companyUserId}
+        </if>
+    </delete>
+    <delete id="deleteCrmCustomerAssistByCustomerId">
+        delete from crm_customer_assist where customer_id = #{customerId}
+    </delete>
+
+</mapper>

+ 3 - 1
fs-service/src/main/resources/mapper/crm/CrmCustomerMapper.xml

@@ -362,7 +362,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY t.type
     </select>
 
-
+    <select id="selectCustomerIdByCompanyUserId" resultType="java.lang.Long">
+        SELECT customer_id FROM crm_customer_assist where company_user_id = #{companyUserId}
+    </select>
 
     <select id="selectCrmMyAssistListQuery" resultType="com.fs.crm.vo.CrmMyCustomerListQueryVO">
         select cu.*,c.create_time as customer_create_time,c.visit_status,c.remark,c.register_desc,c.register_submit_time,