xdd 1 hete
szülő
commit
1ffaa592b0

+ 17 - 0
fs-admin/src/main/java/com/fs/stats/SalesWatchStatisController.java

@@ -1,16 +1,20 @@
 package com.fs.stats;
 
 import com.fs.common.core.domain.R;
+import com.fs.company.service.ICompanyService;
+import com.fs.company.vo.DeptDataVO;
 import com.fs.sop.service.IQwSopService;
 import com.fs.sop.vo.QwSopTask;
 import com.fs.statis.domain.FsStatisSalerWatch;
 import com.fs.statis.dto.StatsWatchLogPageListDTO;
 import com.fs.statis.service.FsStatisSalerWatchService;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 看课统计接口
@@ -26,6 +30,9 @@ public class SalesWatchStatisController {
     @Autowired
     private IQwSopService qwSopService;
 
+    @Autowired
+    private ICompanyService companyService;
+
     /**
      * 销售完播统计查询
      * @param param param
@@ -70,4 +77,14 @@ public class SalesWatchStatisController {
         return R.ok().put("data",qwSopTaskList);
     }
 
+    /**
+     * 获取部门数据
+     * @return
+     */
+    @GetMapping("/getDeptData")
+    public R getDeptData(Long companyId){
+        List<DeptDataVO> data = companyService.getDeptData(companyId);
+        return R.ok().put("data",data);
+    }
+
 }

+ 89 - 0
fs-company/src/main/java/com/fs/stats/SalesWatchStatisController.java

@@ -0,0 +1,89 @@
+package com.fs.stats;
+
+import com.fs.common.core.domain.R;
+import com.fs.company.mapper.CompanyMapper;
+import com.fs.company.service.ICompanyService;
+import com.fs.company.vo.DeptDataVO;
+import com.fs.sop.service.IQwSopService;
+import com.fs.sop.vo.QwSopTask;
+import com.fs.statis.domain.FsStatisSalerWatch;
+import com.fs.statis.dto.StatsWatchLogPageListDTO;
+import com.fs.statis.service.FsStatisSalerWatchService;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 看课统计接口
+ */
+@RestController
+@RequestMapping("/stats")
+@AllArgsConstructor
+public class SalesWatchStatisController {
+
+    @Autowired
+    private FsStatisSalerWatchService fsStatisSalerWatchService;
+
+    @Autowired
+    private IQwSopService qwSopService;
+
+    @Autowired
+    private ICompanyService companyService;
+
+    /**
+     * 销售完播统计查询
+     * @param param param
+     * @return R
+     */
+    @PostMapping("/seller/pageList")
+    public R sellerQueryList(@RequestBody StatsWatchLogPageListDTO param){
+        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryList(param);
+        return R.ok().put("data",list);
+    }
+
+    /**
+     * 训练营完播统计查询
+     * @param param param
+     * @return R
+     */
+    @PostMapping("/period/pageList")
+    public R periodQueryList(@RequestBody StatsWatchLogPageListDTO param){
+        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryPeriodList(param);
+        return R.ok().put("data", list);
+    }
+
+    /**
+     * 每日完播统计查询
+     * @param param param
+     * @return R
+     */
+    @PostMapping("/everyDay/pageList")
+    public R everyDayQueryList(@RequestBody StatsWatchLogPageListDTO param){
+        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryTodayList(param);
+        return R.ok().put("data", list);
+    }
+
+    /**
+     * 获取SOP任务数据
+     * @return
+     */
+    @GetMapping("/sopTaskData")
+    public R getSOPTaskData(){
+        List<QwSopTask> qwSopTaskList = qwSopService.getQwSopTaskList();
+
+        return R.ok().put("data",qwSopTaskList);
+    }
+
+    /**
+     * 获取部门数据
+     * @return
+     */
+    @GetMapping("/getDeptData")
+    public R getDeptData(Long companyId){
+        List<DeptDataVO> data = companyService.getDeptData(companyId);
+        return R.ok().put("data",data);
+    }
+
+}

+ 9 - 0
fs-service-system/src/main/java/com/fs/company/mapper/CompanyDeptMapper.java

@@ -90,4 +90,13 @@ public interface CompanyDeptMapper
      */
     @Select("select cd.* from company_dept cd where cd.company_id = #{companyId} and cd.dept_name = '默认' and cd.parent_id = 0 limit 1")
     CompanyDept getTopCompanyDeptByCompanyId(@Param("companyId") Long companyId);
+
+    /**
+     * 获取所有部门的数据
+     * @param companyId 公司id
+     * @return 部门数据
+     */
+    @Select("select * from company_dept where company_id = ${companyId}")
+    List<CompanyDept> selectDeptDataByCompanyId(@Param("companyId") Long companyId);
+
 }

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

@@ -279,4 +279,6 @@ public interface CompanyUserMapper
 
     Long queryCompanyUserInterruptCount(@Param("companyUserId") Long companyUserId,
                                         @Param("previousDay") LocalDate previousDay);
+
+    List<CompanyUser> selectCompanyUserByDeptId(@Param("deptId") Long deptId);
 }

+ 8 - 4
fs-service-system/src/main/java/com/fs/company/service/ICompanyService.java

@@ -3,10 +3,7 @@ package com.fs.company.service;
 import com.fs.common.core.domain.R;
 import com.fs.company.domain.Company;
 import com.fs.company.param.CompanyParam;
-import com.fs.company.vo.CompanyCrmVO;
-import com.fs.company.vo.CompanyDataVO;
-import com.fs.company.vo.CompanyNameVO;
-import com.fs.company.vo.CompanyVO;
+import com.fs.company.vo.*;
 import com.fs.his.vo.OptionsVO;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStorePayment;
@@ -118,4 +115,11 @@ public interface ICompanyService
 
 
     void subtractCompanyMoney(BigDecimal money, Long companyId);
+
+    /**
+     * 获取部门数据
+     * @param companyId
+     * @return
+     */
+    List<DeptDataVO> getDeptData(Long companyId);
 }

+ 88 - 5
fs-service-system/src/main/java/com/fs/company/service/impl/CompanyServiceImpl.java

@@ -7,10 +7,7 @@ import com.fs.company.domain.*;
 import com.fs.company.mapper.*;
 import com.fs.company.param.CompanyParam;
 import com.fs.company.service.ICompanyService;
-import com.fs.company.vo.CompanyCrmVO;
-import com.fs.company.vo.CompanyDataVO;
-import com.fs.company.vo.CompanyNameVO;
-import com.fs.company.vo.CompanyVO;
+import com.fs.company.vo.*;
 import com.fs.course.mapper.FsCourseRedPacketLogMapper;
 import com.fs.his.vo.OptionsVO;
 import com.fs.store.config.StoreConfig;
@@ -18,6 +15,7 @@ import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStorePayment;
 import com.fs.store.mapper.FsStoreOrderMapper;
 import com.fs.system.service.ISysConfigService;
+import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 企业Service业务层处理
@@ -37,7 +36,7 @@ import java.util.*;
 @Service
 public class CompanyServiceImpl implements ICompanyService
 {
-    Logger logger= LoggerFactory.getLogger(getClass());;
+    Logger logger= LoggerFactory.getLogger(getClass());
     @Autowired
     private CompanyMapper companyMapper;
     @Autowired
@@ -65,6 +64,9 @@ public class CompanyServiceImpl implements ICompanyService
     @Autowired
     private CompanyDeptMapper companyDeptMapper;
 
+    @Autowired
+    private CompanyUserMapper companyUserMapper;
+
 
     @Override
     public List<OptionsVO> selectAllCompanyList() {
@@ -484,5 +486,86 @@ public class CompanyServiceImpl implements ICompanyService
         }
     }
 
+    @Override
+    public List<DeptDataVO> getDeptData(Long companyId) {
+        List<DeptDataVO> result = new ArrayList<>();
+
+        if (companyId != null) {
+            Company company = companyMapper.selectCompanyById(companyId);
+            if (company != null) {
+                DeptDataVO companyNode = buildCompanyNode(company);
+                result.add(companyNode);
+            }
+        } else {
+            List<Company> companies = companyMapper.selectCompanyAllList();
+
+            if (companies != null && !companies.isEmpty()) {
+                for (Company company : companies) {
+                    DeptDataVO companyNode = buildCompanyNode(company);
+                    result.add(companyNode);
+                }
+            }
+        }
+
+        return result.stream().filter(e -> CollectionUtils.isNotEmpty(e.getChildren())).collect(Collectors.toList());
+    }
+    /**
+     * 构建公司节点,包含其下属部门和用户
+     * @param company 公司对象
+     * @return 公司节点
+     */
+    private DeptDataVO buildCompanyNode(Company company) {
+        DeptDataVO companyNode = new DeptDataVO();
+        companyNode.setLabel(company.getCompanyName());
+        companyNode.setId(company.getCompanyId());
+
+        List<DeptDataVO> deptDataList = getCompanyDeptUserData(company.getCompanyId());
+
+        companyNode.setChildren(deptDataList.isEmpty() ? null : deptDataList);
+
+        return companyNode;
+    }
+    /**
+     * 获取公司,以及公司部门、部门下面的销售数据
+     * @return
+     */
+    private List<DeptDataVO> getCompanyDeptUserData(Long companyId){
+        List<CompanyDept> companyDepts = companyDeptMapper.selectDeptDataByCompanyId(companyId);
+
+        if (companyDepts == null || companyDepts.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        List<DeptDataVO> result = new ArrayList<>();
+
+        for (CompanyDept companyDept : companyDepts) {
+            DeptDataVO deptNode = new DeptDataVO();
+            deptNode.setLabel(companyDept.getDeptName());
+            deptNode.setId(companyDept.getDeptId());
+
+            List<CompanyUser> companyUsers =
+                    companyUserMapper.selectCompanyUserByDeptId(companyDept.getDeptId());
+
+            List<DeptDataVO> userNodes = new ArrayList<>();
+
+            if (companyUsers != null && !companyUsers.isEmpty()) {
+                for (CompanyUser companyUser : companyUsers) {
+                    DeptDataVO userNode = new DeptDataVO();
+                    userNode.setLabel(companyUser.getUserName());
+                    userNode.setId(companyUser.getUserId());
+                    userNode.setChildren(null);
+
+                    userNodes.add(userNode);
+                }
+            }
+
+            deptNode.setChildren(userNodes.isEmpty() ? null : userNodes);
+
+            result.add(deptNode);
+        }
+
+        return result;
+    }
+
 
 }

+ 22 - 0
fs-service-system/src/main/java/com/fs/company/vo/DeptDataVO.java

@@ -0,0 +1,22 @@
+package com.fs.company.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class DeptDataVO implements Serializable {
+    /**
+     * 节点名称
+     */
+    private String label;
+    /**
+     * 节点id
+     */
+    private Long id;
+    /**
+     * 子节点
+     */
+    private List<DeptDataVO> children;
+}

+ 13 - 15
fs-service-system/src/main/java/com/fs/sop/service/impl/QwSopServiceImpl.java

@@ -36,6 +36,7 @@ import com.fs.voice.utils.StringUtil;
 import com.fs.wxUser.mapper.CompanyWxUserMapper;
 import com.fs.wxUser.param.CompanyWxUserSopParam;
 import org.apache.commons.collections.ArrayStack;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -112,30 +113,27 @@ public class QwSopServiceImpl implements IQwSopService
 
         for (QwSop qwSop : qwSopList) {
             QwSopTask qwSopTask = new QwSopTask();
-            qwSopTask.setTaskId(qwSop.getId());
-            qwSopTask.setTaskName(qwSop.getName());
+            qwSopTask.setId(qwSop.getId());
+            qwSopTask.setLabel(qwSop.getName());
 
-            List<QwSopTaskDetail> listData = new ArrayList<>();
+            List<QwSopTask> listData = new ArrayList<>();
             // 获取对应SOP任务执行记录
             List<SopUserLogs> sopUserLogs = sopUserLogsMapper.queryExecuteLogBySopId(qwSop.getId());
             for (SopUserLogs sopUserLog : sopUserLogs) {
-                QwSopTaskDetail qwSopTaskDetail = new QwSopTaskDetail();
-                qwSopTaskDetail.setTaskId(sopUserLog.getId());
-                qwSopTaskDetail.setQwUserId(sopUserLog.getQwUserId());
-                qwSopTaskDetail.setTaskExecDate(sopUserLog.getStartTime());
-
-                long daysDifferenceFromNow = DateUtils.getDaysDifferenceFromNow(DateUtils.dateTime("yyyy-MM-dd", sopUserLog.getStartTime()));
-
-                qwSopTaskDetail.setDays(daysDifferenceFromNow);
-
-                listData.add(qwSopTaskDetail);
+                QwSopTask child = new QwSopTask();
+                child.setLabel(sopUserLog.getQwUserId()+"_"+sopUserLog.getStartTime());
+                child.setId(sopUserLog.getId());
+                listData.add(child);
             }
-            qwSopTask.setTaskDetailList(listData);
+            qwSopTask.setChildren(listData);
 
             qwSopTaskList.add(qwSopTask);
         }
+        if(CollectionUtils.isEmpty(qwSopTaskList)){
+            return Collections.emptyList();
+        }
 
-        return qwSopTaskList;
+        return qwSopTaskList.stream().filter(e-> CollectionUtils.isNotEmpty(e.getChildren())).collect(Collectors.toList());
     }
 
     /**

+ 3 - 3
fs-service-system/src/main/java/com/fs/sop/vo/QwSopTask.java

@@ -14,15 +14,15 @@ public class QwSopTask implements Serializable {
     /**
      * 任务id
      */
-    private String taskId;
+    private String id;
 
     /**
      * 任务名称
      */
-    private String taskName;
+    private String label;
 
     /**
      * 任务详情
      */
-    private List<QwSopTaskDetail> taskDetailList;
+    private List<QwSopTask> children;
 }

+ 1 - 1
fs-service-system/src/main/resources/mapper/company/CompanyMapper.xml

@@ -63,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
     <select id="selectCompanyAllList" resultType="com.fs.company.domain.Company">
-        select company_id,company_name where is_del=0
+        select company_id,company_name from company where is_del=0
     </select>
 
     <insert id="insertCompany" parameterType="Company" useGeneratedKeys="true" keyProperty="companyId">

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

@@ -537,6 +537,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
         </where>
     </select>
+    <select id="selectCompanyUserByDeptId" resultType="com.fs.company.domain.CompanyUser">
+        select * from company_user where dept_id = ${deptId} and status='0'
+    </select>
 
     <update id="setIsRegisterMember" parameterType="Long">
         update company_user