Переглянути джерело

分配坐席的时候 多个地方都要处理; 另外额外记录一个新的表【尚辉需要】

王苗苗 3 місяців тому
батько
коміт
5a3bc2b4c9

+ 53 - 0
slibra-system/src/main/java/com/slibra/business/domain/CHumanServiceMap.java

@@ -0,0 +1,53 @@
+package com.slibra.business.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.slibra.common.annotation.Excel;
+import com.slibra.common.core.domain.BaseEntity;
+
+/**
+ * 人工服务组与坐席关系对象 c_human_service_map
+ * 
+ * @author slibra
+ * @date 2024-12-11
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class CHumanServiceMap extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    private String id;
+
+    /** 租户隔离 */
+    @Excel(name = "租户隔离")
+    private String saasId;
+
+    /** 人工组编号 */
+    @Excel(name = "人工组编号")
+    private String serviceId;
+
+    /** 服务类型 */
+    @Excel(name = "服务类型")
+    private String serviceType;
+
+    /** 坐席工号 */
+    @Excel(name = "坐席工号")
+    private String agentId;
+
+    /** 状态 1激活(签入) */
+    @Excel(name = "状态 1激活(签入)")
+    private Long state;
+
+    /** 删除标识 */
+    @Excel(name = "删除标识")
+    private Long isDelete;
+
+}

+ 61 - 0
slibra-system/src/main/java/com/slibra/business/mapper/CHumanServiceMapMapper.java

@@ -0,0 +1,61 @@
+package com.slibra.business.mapper;
+
+import java.util.List;
+import com.slibra.business.domain.CHumanServiceMap;
+
+/**
+ * 人工服务组与坐席关系Mapper接口
+ * 
+ * @author slibra
+ * @date 2024-12-11
+ */
+public interface CHumanServiceMapMapper 
+{
+    /**
+     * 查询人工服务组与坐席关系
+     * 
+     * @param id 人工服务组与坐席关系主键
+     * @return 人工服务组与坐席关系
+     */
+    public CHumanServiceMap selectCHumanServiceMapById(String id);
+
+    /**
+     * 查询人工服务组与坐席关系列表
+     * 
+     * @param cHumanServiceMap 人工服务组与坐席关系
+     * @return 人工服务组与坐席关系集合
+     */
+    public List<CHumanServiceMap> selectCHumanServiceMapList(CHumanServiceMap cHumanServiceMap);
+
+    /**
+     * 新增人工服务组与坐席关系
+     * 
+     * @param cHumanServiceMap 人工服务组与坐席关系
+     * @return 结果
+     */
+    public int insertCHumanServiceMap(CHumanServiceMap cHumanServiceMap);
+
+    /**
+     * 修改人工服务组与坐席关系
+     * 
+     * @param cHumanServiceMap 人工服务组与坐席关系
+     * @return 结果
+     */
+    public int updateCHumanServiceMap(CHumanServiceMap cHumanServiceMap);
+
+    /**
+     * 删除人工服务组与坐席关系
+     * 
+     * @param id 人工服务组与坐席关系主键
+     * @return 结果
+     */
+    public int deleteCHumanServiceMapById(String id);
+
+    /**
+     * 批量删除人工服务组与坐席关系
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteCHumanServiceMapByIds(String[] ids);
+}

+ 86 - 4
slibra-system/src/main/java/com/slibra/system/service/impl/SysRoleServiceImpl.java

@@ -5,7 +5,19 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+
+import com.slibra.business.domain.CAgent;
+import com.slibra.business.domain.CAgentMonitor;
+import com.slibra.business.domain.CHumanServiceMap;
+import com.slibra.business.domain.CPhone;
+import com.slibra.business.mapper.CAgentMapper;
+import com.slibra.business.mapper.CAgentMonitorMapper;
+import com.slibra.business.mapper.CHumanServiceMapMapper;
+import com.slibra.business.mapper.CPhoneMapper;
+import com.slibra.system.mapper.*;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import com.slibra.common.annotation.DataScope;
@@ -19,11 +31,11 @@ import com.slibra.common.utils.spring.SpringUtils;
 import com.slibra.system.domain.SysRoleDept;
 import com.slibra.system.domain.SysRoleMenu;
 import com.slibra.system.domain.SysUserRole;
-import com.slibra.system.mapper.SysRoleDeptMapper;
-import com.slibra.system.mapper.SysRoleMapper;
-import com.slibra.system.mapper.SysRoleMenuMapper;
-import com.slibra.system.mapper.SysUserRoleMapper;
 import com.slibra.system.service.ISysRoleService;
+import org.springframework.util.CollectionUtils;
+
+import static com.slibra.common.constant.MyConstants.SAAS_ID;
+import static com.slibra.common.constant.MyConstants.SIP_PREFIX;
 
 /**
  * 角色 业务层处理
@@ -31,6 +43,7 @@ import com.slibra.system.service.ISysRoleService;
  *
  */
 @Service
+@Slf4j
 public class SysRoleServiceImpl implements ISysRoleService
 {
     @Autowired
@@ -45,6 +58,24 @@ public class SysRoleServiceImpl implements ISysRoleService
     @Autowired
     private SysRoleDeptMapper roleDeptMapper;
 
+    @Autowired
+    private SysUserMapper userMapper;
+
+    @Autowired
+    private CAgentMapper cAgentMapper;
+
+    @Autowired
+    private CAgentMonitorMapper cagentMonitorMapper;
+
+    @Autowired
+    private CPhoneMapper cPhoneMapper;
+
+    @Autowired
+    private CHumanServiceMapMapper cHumanServiceMapMapper;
+
+    @Value("${SIP_SUFFIX}")
+    private String sipSuffix;
+
     /**
      * 根据条件分页查询角色数据
      * 
@@ -408,6 +439,7 @@ public class SysRoleServiceImpl implements ISysRoleService
      * @return 结果
      */
     @Override
+    @Transactional
     public int insertAuthUsers(Long roleId, Long[] userIds)
     {
         // 新增用户与角色管理
@@ -418,7 +450,57 @@ public class SysRoleServiceImpl implements ISysRoleService
             ur.setUserId(userId);
             ur.setRoleId(roleId);
             list.add(ur);
+            //2024年12月11日15:05:06 新增逻辑,判断坐席
+            if(SysUser.isZuoXi(roleId)){
+                SysUser sysUser = this.userMapper.selectUserById(userId);
+                sysUser.setRoleIds(new Long[]{roleId});
+                addZuoXi(sysUser);
+            }
         }
         return userRoleMapper.batchUserRole(list);
     }
+
+
+
+    private void addZuoXi( SysUser user) {
+        Long[] roleIds = user.getRoleIds();
+        boolean isZuoXi = false;
+        if(StringUtils.isNotEmpty(roleIds)){
+            for (Long roleId : roleIds) {
+                if(SysUser.isZuoXi(roleId)){
+                    isZuoXi = true;
+                    break;
+                }
+            }
+        }
+        if(isZuoXi){
+            log.info("当前更新用户的时候,所携带的角色包含坐席的角色");
+            Long userId = user.getUserId();
+            //先去判断在坐席里面,是否已经关联过用户了,如果关联过了,就不需要再增加
+            if(!CollectionUtils.isEmpty(this.cAgentMapper.selectCAgentList(CAgent.builder().userId(userId).build()))){
+                log.info("用户ID{}已经绑定过坐席了,无需重复添加", userId);
+                return;
+            }
+            //没有添加过 添加坐席和坐席监控,并在坐席里插入用户的ID、姓名、密码字段
+            //查询最大的坐席工号 (SQL兜底,有默认值)
+            String maxNum = this.cAgentMapper.selectMaxNum();
+            String agentNum = String.valueOf(Long.parseLong(maxNum) + 1);
+            //坐席对象
+            CAgent cAgent = CAgent.builder().saasId(SAAS_ID).agentNum(agentNum).agentName(user.getNickName()).outId(agentNum).agentPwd(user.getPassword()).phoneNum(agentNum).userId(userId).build();
+            //插入坐席
+            this.cAgentMapper.insertCAgent(cAgent);
+            //坐席监控对象
+            CAgentMonitor cAgentMonitor = CAgentMonitor.builder().saasId(SAAS_ID).agentNum(agentNum).outId(agentNum).build();
+            //插入坐席监控
+            this.cagentMonitorMapper.insertCAgentMonitor(cAgentMonitor);
+            //分机信息对象
+            CPhone cPhone = CPhone.builder().saasId(SAAS_ID).phoneNum(agentNum).sipServer(SIP_PREFIX + agentNum + sipSuffix).build();
+            //插入分机信息
+            this.cPhoneMapper.insertCPhone(cPhone);
+            //2024年12月11日15:02:10 需要插入新的数据
+            CHumanServiceMap cHumanServiceMap = CHumanServiceMap.builder().saasId(SAAS_ID).agentId(agentNum).build();
+            cHumanServiceMapMapper.insertCHumanServiceMap(cHumanServiceMap);
+        }
+
+    }
 }

+ 12 - 0
slibra-system/src/main/java/com/slibra/system/service/impl/SysUserServiceImpl.java

@@ -7,9 +7,11 @@ import javax.validation.Validator;
 
 import com.slibra.business.domain.CAgent;
 import com.slibra.business.domain.CAgentMonitor;
+import com.slibra.business.domain.CHumanServiceMap;
 import com.slibra.business.domain.CPhone;
 import com.slibra.business.mapper.CAgentMapper;
 import com.slibra.business.mapper.CAgentMonitorMapper;
+import com.slibra.business.mapper.CHumanServiceMapMapper;
 import com.slibra.business.mapper.CPhoneMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -80,6 +82,9 @@ public class SysUserServiceImpl implements ISysUserService
     @Autowired
     private CPhoneMapper cPhoneMapper;
 
+    @Autowired
+    private CHumanServiceMapMapper cHumanServiceMapMapper;
+
     @Value("${SIP_SUFFIX}")
     private String sipSuffix;
 
@@ -362,6 +367,9 @@ public class SysUserServiceImpl implements ISysUserService
             CPhone cPhone = CPhone.builder().saasId(SAAS_ID).phoneNum(agentNum).sipServer(SIP_PREFIX + agentNum + sipSuffix).build();
             //插入分机信息
             this.cPhoneMapper.insertCPhone(cPhone);
+            //2024年12月11日15:02:10 需要插入新的数据
+            CHumanServiceMap cHumanServiceMap = CHumanServiceMap.builder().saasId(SAAS_ID).agentId(agentNum).build();
+            cHumanServiceMapMapper.insertCHumanServiceMap(cHumanServiceMap);
         }
 
     }
@@ -377,6 +385,10 @@ public class SysUserServiceImpl implements ISysUserService
     public void insertUserAuth(Long userId, Long[] roleIds)
     {
         userRoleMapper.deleteUserRoleByUserId(userId);
+        //2024年12月11日15:05:06 新增逻辑,判断坐席
+        SysUser sysUser = this.userMapper.selectUserById(userId);
+        sysUser.setRoleIds(roleIds);
+        addZuoXi(sysUser);
         insertUserRole(userId, roleIds);
     }
 

+ 94 - 0
slibra-system/src/main/resources/mapper/business/CHumanServiceMapMapper.xml

@@ -0,0 +1,94 @@
+<?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.slibra.business.mapper.CHumanServiceMapMapper">
+    
+    <resultMap type="CHumanServiceMap" id="CHumanServiceMapResult">
+        <result property="id"    column="id"    />
+        <result property="saasId"    column="saas_id"    />
+        <result property="serviceId"    column="service_id"    />
+        <result property="serviceType"    column="service_type"    />
+        <result property="agentId"    column="agent_id"    />
+        <result property="state"    column="state"    />
+        <result property="isDelete"    column="is_delete"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="createTime"    column="create_time"    />
+    </resultMap>
+
+    <sql id="selectCHumanServiceMapVo">
+        select id, saas_id, service_id, service_type, agent_id, state, is_delete, update_time, create_time from c_human_service_map
+    </sql>
+
+    <select id="selectCHumanServiceMapList" parameterType="CHumanServiceMap" resultMap="CHumanServiceMapResult">
+        <include refid="selectCHumanServiceMapVo"/>
+        <where>
+            1 = 1
+            <if test="saasId != null  and saasId != ''"> and saas_id = #{saasId}</if>
+            <if test="serviceId != null  and serviceId != ''"> and service_id = #{serviceId}</if>
+            <if test="serviceType != null  and serviceType != ''"> and service_type = #{serviceType}</if>
+            <if test="agentId != null  and agentId != ''"> and agent_id = #{agentId}</if>
+            <if test="state != null "> and state = #{state}</if>
+            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
+        </where>
+        and del_flag = 0 order by id desc
+    </select>
+    
+    <select id="selectCHumanServiceMapById" parameterType="String" resultMap="CHumanServiceMapResult">
+        <include refid="selectCHumanServiceMapVo"/>
+        where id = #{id} and del_flag = 0
+    </select>
+        
+    <insert id="insertCHumanServiceMap" parameterType="CHumanServiceMap" useGeneratedKeys="true" keyProperty="id">
+        insert into c_human_service_map
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="saasId != null and saasId != ''">saas_id,</if>
+            <if test="serviceId != null and serviceId != ''">service_id,</if>
+            <if test="serviceType != null and serviceType != ''">service_type,</if>
+            <if test="agentId != null and agentId != ''">agent_id,</if>
+            <if test="state != null">state,</if>
+            <if test="isDelete != null">is_delete,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="createTime != null">create_time,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="saasId != null and saasId != ''">#{saasId},</if>
+            <if test="serviceId != null and serviceId != ''">#{serviceId},</if>
+            <if test="serviceType != null and serviceType != ''">#{serviceType},</if>
+            <if test="agentId != null and agentId != ''">#{agentId},</if>
+            <if test="state != null">#{state},</if>
+            <if test="isDelete != null">#{isDelete},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="createTime != null">#{createTime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateCHumanServiceMap" parameterType="CHumanServiceMap">
+        update c_human_service_map
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="saasId != null and saasId != ''">saas_id = #{saasId},</if>
+            <if test="serviceId != null and serviceId != ''">service_id = #{serviceId},</if>
+            <if test="serviceType != null and serviceType != ''">service_type = #{serviceType},</if>
+            <if test="agentId != null and agentId != ''">agent_id = #{agentId},</if>
+            <if test="state != null">state = #{state},</if>
+            <if test="isDelete != null">is_delete = #{isDelete},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+        </trim>
+        ,revision = revision + 1
+        where id = #{id}
+    </update>
+
+    
+
+    <delete id="deleteCHumanServiceMapById" parameterType="String">
+        update c_human_service_map set del_flag = 2,revision = revision + 1 where del_flag = 0 and id = #{id}
+    </delete>
+
+    <delete id="deleteCHumanServiceMapByIds" parameterType="String">
+        update c_human_service_map set del_flag = 2,revision = revision + 1 where del_flag = 0 and id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>