Jelajahi Sumber

新增联系我的和我联系的统计接口

DESKTOP-VAEGFGM\zqc 11 bulan lalu
induk
melakukan
9494d13ee2

+ 49 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/controller/app/ImStatisticsController.java

@@ -0,0 +1,49 @@
+package com.citu.module.menduner.im.controller.app;
+
+
+import com.citu.framework.common.pojo.CommonResult;
+import com.citu.module.menduner.im.controller.app.base.statistics.ImRecentConversationsStatisticsReqVo;
+import com.citu.module.menduner.im.service.statistics.ImRecentConversationsStatisticsService;
+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.RestController;
+
+/**
+ * @eo.api-type http
+ * @eo.groupName 新门墩.聊天.统计分析
+ * @eo.path
+ */
+
+@RestController
+public class ImStatisticsController {
+
+
+    ImRecentConversationsStatisticsService service;
+
+    /**
+     * @eo.name 联系我的和我联系的统计
+     * @eo.url /im/recent/conversations/statistics
+     * @eo.method post
+     * @eo.request-type json
+     * @param reqVo
+     * @return CommonResult
+     */
+    @PostMapping("/im/recent/conversations/statistics")
+    public CommonResult imRecentConversationsStatistics(@RequestBody ImRecentConversationsStatisticsReqVo reqVo){
+        return service.imRecentConversationsStatistics(reqVo);
+    }
+
+    /**
+     * @eo.name setService
+     * @eo.url
+     * @eo.method get
+     * @eo.request-type formdata
+     * @param service
+     * @return void
+     */
+    @Autowired
+    public void setService(ImRecentConversationsStatisticsService service) {
+        this.service = service;
+    }
+}

+ 76 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/controller/app/base/statistics/ImRecentConversationsStatisticsReqVo.java

@@ -0,0 +1,76 @@
+package com.citu.module.menduner.im.controller.app.base.statistics;
+
+public class ImRecentConversationsStatisticsReqVo {
+
+    /**
+     * 企业id选传
+     */
+
+    private Long enterpriseId;
+
+
+    /**
+     * 企业id选传
+     */
+
+    private Long userId;
+
+
+    /**
+     * 开始时间(秒)
+     */
+    private Long startTime;
+
+
+    /**
+     * 结束时间(秒)
+     */
+    private Long endTime;
+
+    /**
+     * 沟通类型
+     * 0.我发起的
+     * 1.沟通我的
+     */
+    private Integer communicateType=0;
+
+    public Long getEnterpriseId() {
+        return enterpriseId;
+    }
+
+    public void setEnterpriseId(Long enterpriseId) {
+        this.enterpriseId = enterpriseId;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public Long getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Long startTime) {
+        this.startTime = startTime;
+    }
+
+    public Long getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Long endTime) {
+        this.endTime = endTime;
+    }
+
+    public Integer getCommunicateType() {
+        return communicateType;
+    }
+
+    public void setCommunicateType(Integer communicateType) {
+        this.communicateType = communicateType;
+    }
+}

+ 61 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/controller/app/base/statistics/imRecentConversationsStatisticsRespVo.java

@@ -0,0 +1,61 @@
+package com.citu.module.menduner.im.controller.app.base.statistics;
+
+public class imRecentConversationsStatisticsRespVo {
+
+    /**
+     * 主动联系我的数量
+     */
+    private Long activeContactCount;
+
+
+    /**
+     * 主动联系我的 环比
+     */
+    private Double qqactiveContactCount;
+
+
+
+    /**
+     * 主动联系我的数量
+     */
+    private Long usContactCount;
+
+
+    /**
+     * 主动联系我的 环比
+     */
+    private Double qqUsContactCount;
+
+
+    public Long getActiveContactCount() {
+        return activeContactCount;
+    }
+
+    public void setActiveContactCount(Long activeContactCount) {
+        this.activeContactCount = activeContactCount;
+    }
+
+    public Double getQqactiveContactCount() {
+        return qqactiveContactCount;
+    }
+
+    public void setQqactiveContactCount(Double qqactiveContactCount) {
+        this.qqactiveContactCount = qqactiveContactCount;
+    }
+
+    public Long getUsContactCount() {
+        return usContactCount;
+    }
+
+    public void setUsContactCount(Long usContactCount) {
+        this.usContactCount = usContactCount;
+    }
+
+    public Double getQqUsContactCount() {
+        return qqUsContactCount;
+    }
+
+    public void setQqUsContactCount(Double qqUsContactCount) {
+        this.qqUsContactCount = qqUsContactCount;
+    }
+}

+ 18 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/dal/mysql/statistics/ImRecentConversationsStatisticsMapper.java

@@ -0,0 +1,18 @@
+package com.citu.module.menduner.im.dal.mysql.statistics;
+
+import com.citu.module.menduner.im.controller.app.base.statistics.ImRecentConversationsStatisticsReqVo;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+import java.util.Map;
+
+@Mapper
+public interface ImRecentConversationsStatisticsMapper {
+
+    /**
+     * 获取最近会话统计
+     * @param reqVo
+     * @return
+     */
+    List<Map<String,Long>> imRecentConversationsStatistics(ImRecentConversationsStatisticsReqVo reqVo);
+}

+ 8 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/service/statistics/ImRecentConversationsStatisticsService.java

@@ -0,0 +1,8 @@
+package com.citu.module.menduner.im.service.statistics;
+
+import com.citu.framework.common.pojo.CommonResult;
+import com.citu.module.menduner.im.controller.app.base.statistics.ImRecentConversationsStatisticsReqVo;
+
+public interface ImRecentConversationsStatisticsService {
+    CommonResult imRecentConversationsStatistics(ImRecentConversationsStatisticsReqVo reqVo);
+}

+ 78 - 0
menduner/menduner-im-biz/src/main/java/com/citu/module/menduner/im/service/statistics/ImRecentConversationsStatisticsServiceImpl.java

@@ -0,0 +1,78 @@
+package com.citu.module.menduner.im.service.statistics;
+
+import com.citu.framework.common.pojo.CommonResult;
+import com.citu.module.menduner.im.controller.app.base.statistics.ImRecentConversationsStatisticsReqVo;
+import com.citu.module.menduner.im.controller.app.base.statistics.imRecentConversationsStatisticsRespVo;
+import com.citu.module.menduner.im.dal.mysql.statistics.ImRecentConversationsStatisticsMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class ImRecentConversationsStatisticsServiceImpl implements ImRecentConversationsStatisticsService{
+
+    ImRecentConversationsStatisticsMapper mapper;
+
+    @Override
+    public CommonResult imRecentConversationsStatistics(ImRecentConversationsStatisticsReqVo reqVo) {
+        imRecentConversationsStatisticsRespVo resp =new imRecentConversationsStatisticsRespVo();
+        BigDecimal bigDecimal =new BigDecimal("100");
+        reqVo.setCommunicateType(0);  // 我发起的
+        List<Map<String, Long>> maps = mapper.imRecentConversationsStatistics(reqVo);
+        Long currentCount = 0L;  // 本期数量
+        Long parentCount = 0L;  // 上期数量
+        for (int i = 0; i < maps.size(); i++) {
+             Long count =    maps.get(i).get("count");
+             if(i==0){
+                 currentCount=count;
+             }
+            if(i==1){
+                parentCount=count;
+            }
+        }
+
+        resp.setUsContactCount(currentCount);
+        if(currentCount-parentCount==0 ){
+            resp.setQqUsContactCount(0.0);
+        } else if (parentCount==0 ) {
+            resp.setQqUsContactCount(Double.valueOf(currentCount*100));
+        }else if(currentCount == 0){
+            resp.setQqUsContactCount(-Double.valueOf(currentCount*100));
+        }else {
+            resp.setQqUsContactCount(new BigDecimal(currentCount - parentCount).divide(new BigDecimal(parentCount), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).doubleValue());
+        }
+        reqVo.setCommunicateType(1);  // 我发起的
+        List<Map<String, Long>> maps2 = mapper.imRecentConversationsStatistics(reqVo);
+         currentCount = 0L;
+         parentCount = 0L;
+        for (int i = 0; i < maps.size(); i++) {
+            Long count =    maps.get(i).get("count");
+            if(i==0){
+                currentCount=count;
+            }
+            if(i==1){
+                parentCount=count;
+            }
+        }
+        resp.setActiveContactCount(currentCount);
+        if(currentCount-parentCount==0  || parentCount == 0 || currentCount ==0){
+            resp.setQqactiveContactCount(0.0);
+        }else if (parentCount==0 ) {
+            resp.setQqactiveContactCount(Double.valueOf(currentCount*100));
+        }else if(currentCount == 0){
+            resp.setQqactiveContactCount(-Double.valueOf(currentCount*100));
+        }else {
+            resp.setQqactiveContactCount(new BigDecimal(currentCount - parentCount).divide(new BigDecimal(parentCount), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).doubleValue());
+        }
+        return CommonResult.success(resp);
+    }
+
+
+    @Autowired
+    public void setMapper(ImRecentConversationsStatisticsMapper mapper) {
+        this.mapper = mapper;
+    }
+}

+ 63 - 0
menduner/menduner-im-biz/src/main/resources/mapper/statistics/ImRecentConversationsStatisticsMapper.xml

@@ -0,0 +1,63 @@
+<?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.citu.module.menduner.im.dal.mysql.statistics.ImRecentConversationsStatisticsMapper">
+
+
+    <select id="imRecentConversationsStatistics" resultType="java.util.Map">
+        SELECT
+            count(1) as count
+        FROM
+            `im_user` u inner join im_user_msg  msg
+            <if test="0==communicateType">
+                on u.uid = msg.from_uid
+            </if>
+            <if test="1==communicateType">
+                on u.uid = msg.channel_id
+            </if>
+        <where>
+            msg.message_seq='1'
+            <if test="userId != null">
+              and   u.user_id = #{userId}
+            </if>
+            <if test="enterpriseId != null">
+                and   u.enterprise_id = #{enterpriseId}
+            </if>
+            <if test="startTime != null">
+                and   msg.timestamp >= #{startTime}
+            </if>
+            <if test="endTime != null">
+                and   msg.timestamp &lt;= #{endTime}
+            </if>
+        </where>
+        union all
+        SELECT
+        count(1) as count
+        FROM
+        `im_user` u inner join im_user_msg  msg
+        <if test="0==communicateType">
+            on u.uid = msg.from_uid
+        </if>
+        <if test="1==communicateType">
+            on u.uid = msg.channel_id
+        </if>
+        <where>
+            msg.message_seq='1'
+            <if test="userId != null">
+                and   u.user_id = #{userId}
+            </if>
+            <if test="enterpriseId != null">
+                and   u.enterprise_id = #{enterpriseId}
+            </if>
+            <if test="startTime != null">
+                and   msg.timestamp >= (#{startTime}-(#{endTime}-#{startTime}))
+            </if>
+            <if test="endTime != null">
+                and   msg.timestamp &lt;= #{startTime}
+            </if>
+        </where>
+
+
+
+
+     </select>
+</mapper>