Просмотр исходного кода

1.企微员工界面增加ai客服上线下线功能
2.修复致医销售端无法展示首页统计图问题

jzp 13 часов назад
Родитель
Сommit
86f1171dc9

+ 89 - 5
fs-company/src/main/java/com/fs/company/controller/company/IndexStatisticsController.java

@@ -3,6 +3,9 @@ package com.fs.company.controller.company;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.ServletUtils;
+import com.fs.company.domain.Company;
+import com.fs.company.service.ICompanyService;
+import com.fs.config.cloud.CloudHostProper;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
 import com.fs.statis.StatisticsRedisConstant;
@@ -12,7 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 import static com.fs.statis.StatisticsRedisConstant.*;
 
@@ -31,6 +37,11 @@ public class IndexStatisticsController {
     @Autowired
     private IStatisticsService statisticsService;
 
+    @Autowired
+    private ICompanyService companyService;
+
+    @Autowired
+    CloudHostProper cloudHostProper;
     /**
      * 分析概览
      */
@@ -94,12 +105,85 @@ public class IndexStatisticsController {
             userType = 0;
         }
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-        Long companyId = loginUser.getCompany().getCompanyId();
-        param.setCompanyId(companyId);
 
-        String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
-        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
-        return R.ok().put("data", deaMemberTopTenDTOS);
+        if("四川致医".equals(cloudHostProper.getCompanyName())){
+            Long companyId1 = loginUser.getCompany().getCompanyId();
+            Company company = loginUser.getCompany();
+            param.setCompanyId(companyId1);
+            List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS;
+
+            // 参考watchCourseTopTen方法的处理逻辑
+            if ((param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
+                String key = String.format("%s:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType);
+                watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
+            }else if(param.getCompanyId() != null){
+                String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
+                watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
+            }else{
+                Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
+                List<WatchEndPlayTrendDTO> tempDTOS = new ArrayList<>();
+                for(Long companyId : companyIds){
+                    String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,companyId);
+                    List<WatchEndPlayTrendDTO> companyData = redisCache.getCacheObject(key);
+                    if (companyData != null) {
+                        tempDTOS.addAll(companyData);
+                    }
+                }
+                // 根据startDate 和 x 分组,合并watchUserCount和completedUserCount 限制最多返回10条记录
+                watchEndPlayTrendDTOS = tempDTOS.stream()
+                        .collect(Collectors.groupingBy(
+                                dto -> dto.getStartDate() + ":" + dto.getX(),  // 根据startDate和x分组
+                                Collectors.reducing(new WatchEndPlayTrendDTO(), (dto1, dto2) -> {
+                                    // 合并watchUserCount和completedUserCount
+                                    WatchEndPlayTrendDTO result = new WatchEndPlayTrendDTO();
+                                    // 复制分组标识字段
+                                    if (dto2 != null && dto2.getStartDate() != null) {
+                                        result.setStartDate(dto2.getStartDate());
+                                    } else if (dto1 != null) {
+                                        result.setStartDate(dto1.getStartDate());
+                                    }
+
+                                    if (dto2 != null && dto2.getX() != null) {
+                                        result.setX(dto2.getX());
+                                    } else if (dto1 != null) {
+                                        result.setX(dto1.getX());
+                                    }
+
+                                    // 合并数值字段
+                                    result.setWatchUserCount(
+                                            (dto1 == null || dto1.getWatchUserCount() == null ? 0 : dto1.getWatchUserCount()) +
+                                                    (dto2 == null || dto2.getWatchUserCount() == null ? 0 : dto2.getWatchUserCount())
+                                    );
+
+                                    result.setCompletedUserCount(
+                                            (dto1 == null || dto1.getCompletedUserCount() == null ? 0 : dto1.getCompletedUserCount()) +
+                                                    (dto2 == null || dto2.getCompletedUserCount() == null ? 0 : dto2.getCompletedUserCount())
+                                    );
+
+                                    return result;
+                                })
+                        ))
+                        .values()
+                        .stream()
+                        .filter(Objects::nonNull)  // 过滤掉null值
+                        .limit(10)
+                        .sorted(Comparator.comparing(WatchEndPlayTrendDTO::getX))
+                        .collect(Collectors.toList());
+            }
+
+            if(watchEndPlayTrendDTOS == null){
+                watchEndPlayTrendDTOS = new ArrayList<>();
+            }
+
+            return R.ok().put("data", watchEndPlayTrendDTOS);
+        }else{
+            Long companyId = loginUser.getCompany().getCompanyId();
+            param.setCompanyId(companyId);
+
+            String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
+            List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
+            return R.ok().put("data", deaMemberTopTenDTOS);
+        }
     }
 
     /**

+ 6 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwUserController.java

@@ -952,4 +952,10 @@ public class QwUserController extends BaseController
         List<QwUserVO> list = qwUserService.selectQwUserListByCompanyIdAndCorpIdAndNickName(companyId, corpId, nickName);
         return getDataTable(list);
     }
+
+    @GetMapping("/updateFastGptRoleStatusById/{id}")
+    public R updateFastGptRoleStatusById(@PathVariable Long id)
+    {
+        return qwUserService.updateQwUserFastGptRoleStatusById(id);
+    }
 }

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

@@ -351,4 +351,5 @@ public interface CompanyUserMapper
      */
     List<com.fs.hisStore.domain.FsUserScrm> selectBoundFsUsersByCompanyUserId(@Param("companyUserId") Long companyUserId);
 
+    CompanyUser selectCompanyUserByQwUserId(@Param("qwUserId") Long id);
 }

+ 26 - 0
fs-service/src/main/java/com/fs/fastGpt/service/impl/AiHookServiceImpl.java

@@ -9,8 +9,11 @@ import com.fs.common.config.FSConfig;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.company.domain.CompanyConfig;
+import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyConfigMapper;
+import com.fs.company.mapper.CompanyUserMapper;
 import com.fs.config.ai.AiHostProper;
+import com.fs.config.cloud.CloudHostProper;
 import com.fs.course.domain.FsUserCourseVideo;
 import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.fs.course.mapper.FsUserCourseVideoMapper;
@@ -169,6 +172,12 @@ public class AiHookServiceImpl implements AiHookService {
     @Autowired
     private ICrmMsgService crmMsgService;
 
+    @Autowired
+    private CompanyUserMapper companyUserMapper;
+
+    @Autowired
+    private CloudHostProper cloudHostProper;
+
     private static final String AI_REPLY = "AI_REPLY:";
     private static final String AI_REPLY_TAG = "AI_REPLY_TAG:";
 
@@ -392,6 +401,12 @@ public class AiHookServiceImpl implements AiHookService {
             log.error("未绑定角色");
             return userIsReply(sender, uid, user);
         }
+
+        if(user.getAiStatus() == 1){
+            log.error("ai已下线:{}",user);
+            return R.ok();
+        }
+
         Long serverId = user.getServerId();
         log.info("服务器id"+serverId);
         if (serverId == null) {
@@ -1469,6 +1484,17 @@ public class AiHookServiceImpl implements AiHookService {
             //添加看客记录
             addCourseWatchLog(qwExternalContactsId);
             String msgC = (String)redisCache.getCacheObject("msg:" + fastGptChatSession.getSessionId());
+
+            if (("今正科技".equals(cloudHostProper.getCompanyName()))) {
+                //处理名称替换
+                if (role.getReminderWords() != null && !role.getReminderWords().isEmpty() && role.getReminderWords().contains("#销售名称#")) {
+                    CompanyUser companyUser = companyUserMapper.selectCompanyUserByQwUserId(user.getId());
+                    if (companyUser != null) {
+                        role.setReminderWords(role.getReminderWords().replace("#销售名称#", companyUser.getNickName()));
+                    }
+                }
+            }
+
             //添加关键词
             addPromptWord(messageList,msgC,qwExternalContactsId,role.getReminderWords(), role.getContactInfo(),fastGptChatSession.getSessionId());
             R r = chatService.initiatingTakeChat(param, aiHostProper.getAiApi(), appKey);

+ 3 - 0
fs-service/src/main/java/com/fs/qw/domain/QwUser.java

@@ -113,4 +113,7 @@ public class QwUser extends BaseEntity
 
     @TableField(exist = false)
     private Integer disableCompanyId;
+
+    //根据ai状态判断是否启用
+    private Integer aiStatus;
 }

+ 1 - 0
fs-service/src/main/java/com/fs/qw/service/IQwUserService.java

@@ -208,4 +208,5 @@ public interface IQwUserService
 
     R unbindQwUserByServerIds(List<String> serverIds);
 
+    R updateQwUserFastGptRoleStatusById(Long id);
 }

+ 18 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwUserServiceImpl.java

@@ -1625,6 +1625,24 @@ public class QwUserServiceImpl implements IQwUserService
         return R.ok();
     }
 
+    @Override
+    public R updateQwUserFastGptRoleStatusById(Long id) {
+        QwUser qwUser = qwUserMapper.selectQwUserById(id);
+        if(qwUser != null){
+            Integer aiStatus = qwUser.getAiStatus() == 0 ? 1 : 0;
+            QwUser qwUserNew = new QwUser();
+            qwUserNew.setId(id);
+            qwUserNew.setAiStatus(aiStatus);
+            int i = qwUserMapper.updateQwUser(qwUserNew);
+            if (i > 0) {
+                return R.ok("修改成功");
+            }else {
+                return R.error("修改失败");
+            }
+        }
+        return R.error("修改失败,未找到企微!");
+    }
+
     /**
      * 根据销售公司和企微ID查询企微用户
      */

+ 2 - 0
fs-service/src/main/java/com/fs/qw/vo/QwUserVO.java

@@ -118,4 +118,6 @@ public class QwUserVO {
     private Long doctorId;
 
     private Integer videoGetStatus;
+
+    private Integer aiStatus;
 }

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

@@ -732,5 +732,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE bind_company_user_id = #{companyUserId}
         AND is_del = 0
     </select>
+    <select id="selectCompanyUserByQwUserId" resultType="com.fs.company.domain.CompanyUser">
+        SELECT * FROM company_user
+        WHERE FIND_IN_SET(#{qwUserId}, qw_user_id) > 0
+        order by create_time desc
+            limit 1
+    </select>
 
 </mapper>

+ 7 - 1
fs-service/src/main/resources/mapper/qw/QwUserMapper.xml

@@ -35,10 +35,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isAuto"    column="is_auto"    />
         <result property="videoGetStatus"    column="video_get_status"    />
         <result property="updateTime"    column="update_time"    />
+        <result property="aiStatus"    column="ai_status"    />
     </resultMap>
 
     <sql id="selectQwUserVo">
-        select id,is_auto, video_get_status, qw_user_id,server_id,server_status,ipad_status,config_id,vid,uid,contact_way,app_key, qw_user_name, department, openid, company_id, company_user_id, corp_id, status, is_del, welcome_text, welcome_image, is_send_msg,app_key,qw_hook_id,fastGpt_role_id,login_status,tool_status,login_code_url,version,update_time from qw_user
+        select id,is_auto, video_get_status, qw_user_id,server_id,server_status,
+               ipad_status,config_id,vid,uid,contact_way,app_key, qw_user_name, department,
+               openid, company_id, company_user_id, corp_id, status, is_del, welcome_text,
+               welcome_image, is_send_msg,app_key,qw_hook_id,fastGpt_role_id,login_status,
+               tool_status,login_code_url,version,update_time,ai_status from qw_user
         </sql>
 
     <select id="selectQwUserList" parameterType="QwUser" resultMap="QwUserResult">
@@ -178,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="serverStatus != null">server_status = #{serverStatus},</if>
             <if test="isAuto != null">is_auto = #{isAuto},</if>
             <if test="videoGetStatus != null">video_get_status = #{videoGetStatus},</if>
+            <if test="aiStatus != null">ai_status = #{aiStatus},</if>
         </trim>
         where id = #{id}
     </update>