Browse Source

保存角色的时候 如果包含’坐席‘这个角色 如果是用户第一次添加该角色,需要同时插入坐席表和坐席监控表

王苗苗 2 days ago
parent
commit
a0d370f808

+ 3 - 0
slibra-common/src/main/java/com/slibra/common/constant/MyConstants.java

@@ -115,6 +115,9 @@ public class MyConstants {
     //温度的范围  超过该温度表示夏季;没有超过表示冬季
     public static final String TEMPERATURE_VALUE = "12";
 
+    //坐席的分区标识
+    public static final String SAAS_ID = "mdj";
+
 
     public static final String WARNING_TEMPLATE = "您有#个报警信息,请解决";
     public static final String FORECAST_WARNING_TEMPLATE = "您有#个预警信息,请解决";

+ 11 - 0
slibra-common/src/main/java/com/slibra/common/core/domain/entity/SysUser.java

@@ -477,4 +477,15 @@ public class SysUser extends BaseEntity
             .append("dept", getDept())
             .toString();
     }
+
+    //2024年11月25日10:48:02 固定一个ID 判断是不是坐席
+    public boolean isZuoXi()
+    {
+        return isZuoXi(this.roleId);
+    }
+
+    public static boolean isZuoXi(Long roleId)
+    {
+        return roleId != null && 106L == roleId;
+    }
 }

+ 2 - 0
slibra-system/src/main/java/com/slibra/business/mapper/CAgentMapper.java

@@ -58,4 +58,6 @@ public interface CAgentMapper
      * @return 结果
      */
     public int deleteCAgentByIds(String[] ids);
+
+    String selectMaxNum();
 }

+ 0 - 2
slibra-system/src/main/java/com/slibra/business/service/impl/CAgentMonitorServiceImpl.java

@@ -53,7 +53,6 @@ public class CAgentMonitorServiceImpl implements ICAgentMonitorService
     @Override
     public int insertCAgentMonitor(CAgentMonitor cAgentMonitor)
     {
-        cAgentMonitor.setCreateTime(DateUtils.getNowDate());
         return cAgentMonitorMapper.insertCAgentMonitor(cAgentMonitor);
     }
 
@@ -66,7 +65,6 @@ public class CAgentMonitorServiceImpl implements ICAgentMonitorService
     @Override
     public int updateCAgentMonitor(CAgentMonitor cAgentMonitor)
     {
-        cAgentMonitor.setUpdateTime(DateUtils.getNowDate());
         return cAgentMonitorMapper.updateCAgentMonitor(cAgentMonitor);
     }
 

+ 0 - 2
slibra-system/src/main/java/com/slibra/business/service/impl/CAgentServiceImpl.java

@@ -53,7 +53,6 @@ public class CAgentServiceImpl implements ICAgentService
     @Override
     public int insertCAgent(CAgent cAgent)
     {
-        cAgent.setCreateTime(DateUtils.getNowDate());
         return cAgentMapper.insertCAgent(cAgent);
     }
 
@@ -66,7 +65,6 @@ public class CAgentServiceImpl implements ICAgentService
     @Override
     public int updateCAgent(CAgent cAgent)
     {
-        cAgent.setUpdateTime(DateUtils.getNowDate());
         return cAgentMapper.updateCAgent(cAgent);
     }
 

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

@@ -4,6 +4,11 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
+
+import com.slibra.business.domain.CAgent;
+import com.slibra.business.domain.CAgentMonitor;
+import com.slibra.business.mapper.CAgentMapper;
+import com.slibra.business.mapper.CAgentMonitorMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +36,7 @@ import com.slibra.system.service.ISysConfigService;
 import com.slibra.system.service.ISysUserService;
 
 import static com.slibra.common.constant.MyConstants.LOGIN_TYPE_APPEND;
+import static com.slibra.common.constant.MyConstants.SAAS_ID;
 
 /**
  * 用户 业务层处理
@@ -63,6 +69,12 @@ public class SysUserServiceImpl implements ISysUserService
     @Autowired
     protected Validator validator;
 
+    @Autowired
+    private CAgentMapper cAgentMapper;
+
+    @Autowired
+    private CAgentMonitorMapper cagentMonitorMapper;
+
     /**
      * 根据条件分页查询用户列表
      * 
@@ -302,9 +314,46 @@ public class SysUserServiceImpl implements ISysUserService
         userPostMapper.deleteUserPostByUserId(userId);
         // 新增用户与岗位管理
         insertUserPost(user);
+        //2024年11月25日10:51:14 在分配用户角色的时候,如果角色包含”坐席“,那么需要额外保存到数据库中2条坐席相关的记录
+        addZuoXi(user);
         return userMapper.updateUser(user);
     }
 
+    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);
+        }
+
+    }
+
     /**
      * 用户授权角色
      * 

+ 9 - 2
slibra-system/src/main/resources/mapper/business/CAgentMapper.xml

@@ -17,8 +17,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="agentState"    column="agent_state"    />
         <result property="identityType"    column="identity_type"    />
         <result property="isDelete"    column="is_delete"    />
-        <result property="updateTime"    column="update_time"    />
-        <result property="createTime"    column="create_time"    />
         <result property="userId"    column="user_id"    />
     </resultMap>
 
@@ -121,4 +119,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <!-- 2024年11月25日11:03:19 下面是新增的SQL,不允许覆盖 -->
+    <select id="selectMaxNum" resultType="string">
+        SELECT
+            IFNULL( MAX( agent_num ), '1000' )
+        FROM
+            c_agent
+        WHERE is_delete = 0
+    </select>
 </mapper>

+ 0 - 2
slibra-system/src/main/resources/mapper/business/CAgentMonitorMapper.xml

@@ -23,8 +23,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="heartTime"    column="heart_time"    />
         <result property="sessionId"    column="session_id"    />
         <result property="isDelete"    column="is_delete"    />
-        <result property="updateTime"    column="update_time"    />
-        <result property="createTime"    column="create_time"    />
     </resultMap>
 
     <sql id="selectCAgentMonitorVo">