1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix AgentUserRepository related class

This commit is contained in:
dengchao@xgtl 2020-04-16 14:33:30 +08:00
parent af069c4363
commit 1644826f5b
11 changed files with 994 additions and 1166 deletions

View File

@ -27,55 +27,59 @@ import com.chatopera.cc.socketio.client.NettyClients;
import com.chatopera.cc.util.SerializeUtil; import com.chatopera.cc.util.SerializeUtil;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener; import org.springframework.jms.annotation.JmsListener;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Optional;
/** /**
* 会话监控 * 会话监控
*/ */
@Component @Component
@RequiredArgsConstructor
public class AgentAuditSubscription { public class AgentAuditSubscription {
private final static Logger logger = LoggerFactory.getLogger(AgentAuditSubscription.class); private final static Logger logger = LoggerFactory.getLogger(AgentAuditSubscription.class);
@Autowired @NonNull
private Cache cache; private final Cache cache;
@Autowired @NonNull
private AgentAuditProxy agentAuditProxy; private final AgentAuditProxy agentAuditProxy;
@Autowired @NonNull
private AgentUserRepository agentUserRes; private final AgentUserRepository agentUserRes;
/** /**
* 接收坐席会话监控消息 * 接收坐席会话监控消息
*
* @param msg
*/ */
@JmsListener(destination = Constants.AUDIT_AGENT_MESSAGE, containerFactory = "jmsListenerContainerTopic") @JmsListener(destination = Constants.AUDIT_AGENT_MESSAGE, containerFactory = "jmsListenerContainerTopic")
public void onMessage(final String msg) { public void onMessage(final String msg) {
logger.info("[onMessage] payload {}", msg); logger.info("[onMessage] payload {}", msg);
try { try {
final JsonObject json = new JsonParser().parse(msg).getAsJsonObject(); final JsonObject json = JsonParser.parseString(msg).getAsJsonObject();
if (json.has("orgi") && json.has("data") && if (json.has("orgi") && json.has("data") &&
json.has("agentUserId") && json.has("agentUserId") &&
json.has("event") && json.has("agentno")) { json.has("event") && json.has("agentno")) {
// 查找关联的会话监控信息 // 查找关联的会话监控信息
String agentUserId = json.get("agentUserId").getAsString();
final AgentUserAudit agentUserAudit = cache.findOneAgentUserAuditByOrgiAndId( final AgentUserAudit agentUserAudit = cache.findOneAgentUserAuditByOrgiAndId(
json.get("orgi").getAsString(), json.get("orgi").getAsString(),
json.get("agentUserId").getAsString()).orElseGet(() -> { agentUserId).orElseGet(() -> {
final AgentUser agentUser = agentUserRes.findOne(json.get("agentUserId").getAsString()); Optional<AgentUser> optional = agentUserRes.findById(agentUserId);
if (agentUser != null) { if (optional.isPresent()) {
final AgentUser agentUser = optional.get();
return agentAuditProxy.updateAgentUserAudits(agentUser); return agentAuditProxy.updateAgentUserAudits(agentUser);
} else { } else {
logger.warn( logger.warn(
"[onMessage] can not find agent user by id {}", json.get("agentUserId").getAsString()); "[onMessage] can not find agent user by id {}", agentUserId);
} }
return null; return null;
}); });
@ -101,7 +105,7 @@ public class AgentAuditSubscription {
} else { } else {
logger.warn( logger.warn(
"[onMessage] can not resolve agent user audit object for agent user id {}", "[onMessage] can not resolve agent user audit object for agent user id {}",
json.get("agentUserId").getAsString()); agentUserId);
} }
} else { } else {
throw new CSKefuException("Invalid payload."); throw new CSKefuException("Invalid payload.");

View File

@ -23,34 +23,51 @@ import com.chatopera.cc.persistence.repository.AgentUserRepository;
import com.chatopera.cc.persistence.repository.OnlineUserRepository; import com.chatopera.cc.persistence.repository.OnlineUserRepository;
import com.chatopera.cc.util.SerializeUtil; import com.chatopera.cc.util.SerializeUtil;
import com.chatopera.cc.util.freeswitch.model.CallCenterAgent; import com.chatopera.cc.util.freeswitch.model.CallCenterAgent;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
@Component @Component
@RequiredArgsConstructor
public class Cache { public class Cache {
final static private Logger logger = LoggerFactory.getLogger(Cache.class); final static private Logger logger = LoggerFactory.getLogger(Cache.class);
@Autowired @NonNull
private OnlineUserRepository onlineUserRes; private final OnlineUserRepository onlineUserRes;
@Autowired @NonNull
private AgentUserRepository agentUserRes; private final AgentUserRepository agentUserRes;
@Autowired @NonNull
private RedisCommand redisCommand; private final RedisCommand redisCommand;
/**
* Inline方法
*/
private static Map<String, AgentStatus> convertFromStringToAgentStatus(final Map<String, String> map) {
Map<String, AgentStatus> result = new HashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) {
AgentStatus obj = SerializeUtil.deserialize(entry.getValue());
result.put(entry.getKey(), obj);
}
return result;
}
private static OnlineUser convertFromStringToOnlineUser(final String serialized) {
return SerializeUtil.deserialize(serialized);
}
/** /**
* 获得就绪的坐席列表 * 获得就绪的坐席列表
* *
* @param orgi 租户 * @param orgi 租户
* @return
*/ */
public Map<String, AgentStatus> getAgentStatusReadyByOrig(final String orgi) { public Map<String, AgentStatus> getAgentStatusReadyByOrig(final String orgi) {
Map<String, String> agentStatuses = redisCommand.getHash(RedisKey.getAgentStatusReadyHashKey(orgi)); Map<String, String> agentStatuses = redisCommand.getHash(RedisKey.getAgentStatusReadyHashKey(orgi));
@ -59,23 +76,19 @@ public class Cache {
/** /**
* 通过访客ID和ORGI获得访客坐席关联关系 * 通过访客ID和ORGI获得访客坐席关联关系
*
* @param userId
* @param orgi
* @return
*/ */
public Optional<AgentUser> findOneAgentUserByUserIdAndOrgi(final String userId, final String orgi) { public Optional<AgentUser> findOneAgentUserByUserIdAndOrgi(final String userId, final String orgi) {
if (redisCommand.hasHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userId)) { if (redisCommand.hasHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userId)) {
// 排队等待中 // 排队等待中
return Optional.ofNullable((AgentUser) SerializeUtil.deserialize( return Optional.ofNullable(SerializeUtil.deserialize(
redisCommand.getHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userId))); redisCommand.getHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userId)));
} else if (redisCommand.hasHashKV(RedisKey.getAgentUserInServHashKey(orgi), userId)) { } else if (redisCommand.hasHashKV(RedisKey.getAgentUserInServHashKey(orgi), userId)) {
// 服务中 // 服务中
return Optional.ofNullable((AgentUser) SerializeUtil.deserialize( return Optional.ofNullable(SerializeUtil.deserialize(
redisCommand.getHashKV(RedisKey.getAgentUserInServHashKey(orgi), userId))); redisCommand.getHashKV(RedisKey.getAgentUserInServHashKey(orgi), userId)));
} else if (redisCommand.hasHashKV(RedisKey.getAgentUserEndHashKey(orgi), userId)) { } else if (redisCommand.hasHashKV(RedisKey.getAgentUserEndHashKey(orgi), userId)) {
// 已经结束 // 已经结束
return Optional.ofNullable((AgentUser) SerializeUtil.deserialize( return Optional.ofNullable(SerializeUtil.deserialize(
redisCommand.getHashKV(RedisKey.getAgentUserEndHashKey(orgi), userId))); redisCommand.getHashKV(RedisKey.getAgentUserEndHashKey(orgi), userId)));
} else { } else {
// 缓存中没有找到继续到数据库查找 // 缓存中没有找到继续到数据库查找
@ -83,19 +96,15 @@ public class Cache {
} }
} }
/** /**
* 返回排队中的客服列表 * 返回排队中的客服列表
*
* @param orgi
* @return
*/ */
public Map<String, AgentUser> getAgentUsersInQueByOrgi(final String orgi) { public Map<String, AgentUser> getAgentUsersInQueByOrgi(final String orgi) {
Map<String, String> agentUsers = redisCommand.getHash(RedisKey.getAgentUserInQueHashKey(orgi)); Map<String, String> agentUsers = redisCommand.getHash(RedisKey.getAgentUserInQueHashKey(orgi));
Map<String, AgentUser> map = new HashMap<>(); Map<String, AgentUser> map = new HashMap<>();
for (final Map.Entry<String, String> entry : agentUsers.entrySet()) { for (final Map.Entry<String, String> entry : agentUsers.entrySet()) {
final AgentUser obj = SerializeUtil.deserialize(entry.getValue()); final AgentUser obj = SerializeUtil.deserialize(entry.getValue());
map.put(obj.getId(), obj); map.put(Objects.requireNonNull(obj).getId(), obj);
} }
return map; return map;
} }
@ -103,20 +112,13 @@ public class Cache {
/** /**
* 将访客ID从服务中队列中删除 * 将访客ID从服务中队列中删除
* TODO 将访客对应的客服的服务列表变更 * TODO 将访客对应的客服的服务列表变更
*
* @param userid
* @param orgi
*/ */
public void deleteAgentUserInservByAgentUserIdAndOrgi(final String userid, final String orgi) { public void deleteAgentUserInservByAgentUserIdAndOrgi(final String userid, final String orgi) {
redisCommand.delHashKV(RedisKey.getAgentUserInServHashKey(orgi), userid); redisCommand.delHashKV(RedisKey.getAgentUserInServHashKey(orgi), userid);
} }
/** /**
* 将访客ID从排队队列中删除 * 将访客ID从排队队列中删除
*
* @param userid
* @param orgi
*/ */
public void deleteAgentUserInqueByAgentUserIdAndOrgi(final String userid, final String orgi) { public void deleteAgentUserInqueByAgentUserIdAndOrgi(final String userid, final String orgi) {
redisCommand.delHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userid); redisCommand.delHashKV(RedisKey.getAgentUserInQueHashKey(orgi), userid);
@ -127,7 +129,6 @@ public class Cache {
* *
* @param agentno 坐席ID * @param agentno 坐席ID
* @param orgi 租户ID * @param orgi 租户ID
* @return
*/ */
public AgentStatus findOneAgentStatusByAgentnoAndOrig(final String agentno, final String orgi) { public AgentStatus findOneAgentStatusByAgentnoAndOrig(final String agentno, final String orgi) {
String status = getAgentStatusStatus(agentno, orgi); String status = getAgentStatusStatus(agentno, orgi);
@ -140,15 +141,12 @@ public class Cache {
String val = redisCommand.getHashKV(RedisKey.getAgentStatusHashKeyByStatusStr(orgi, status), agentno); String val = redisCommand.getHashKV(RedisKey.getAgentStatusHashKeyByStatusStr(orgi, status), agentno);
AgentStatus result = SerializeUtil.deserialize(val); AgentStatus result = SerializeUtil.deserialize(val);
logger.debug("[findOneAgentStatusByAgentnoAndOrig] result: username {}", result.getUsername()); logger.debug("[findOneAgentStatusByAgentnoAndOrig] result: username {}", Objects.requireNonNull(result).getUsername());
return result; return result;
} }
/** /**
* 更新坐席状态 * 更新坐席状态
*
* @param agentStatus
* @param orgi
*/ */
public void putAgentStatusByOrgi(AgentStatus agentStatus, String orgi) { public void putAgentStatusByOrgi(AgentStatus agentStatus, String orgi) {
String pre = getAgentStatusStatus(agentStatus.getAgentno(), orgi); // 坐席前状态 String pre = getAgentStatusStatus(agentStatus.getAgentno(), orgi); // 坐席前状态
@ -160,14 +158,12 @@ public class Cache {
RedisKey.getAgentStatusHashKeyByStatusStr(orgi, agentStatus.getStatus()), RedisKey.getAgentStatusHashKeyByStatusStr(orgi, agentStatus.getStatus()),
agentStatus.getAgentno(), SerializeUtil.serialize(agentStatus)); agentStatus.getAgentno(), SerializeUtil.serialize(agentStatus));
} }
return;
} else { } else {
// 之前存在与将要更新的状态一致 // 之前存在与将要更新的状态一致
if (StringUtils.equals(pre, agentStatus.getStatus())) { if (StringUtils.equals(pre, agentStatus.getStatus())) {
redisCommand.setHashKV( redisCommand.setHashKV(
RedisKey.getAgentStatusHashKeyByStatusStr(orgi, pre), agentStatus.getAgentno(), RedisKey.getAgentStatusHashKeyByStatusStr(orgi, pre), agentStatus.getAgentno(),
SerializeUtil.serialize(agentStatus)); SerializeUtil.serialize(agentStatus));
return;
} else { } else {
// 之前存在而且与新状态不一致 // 之前存在而且与新状态不一致
redisCommand.delHashKV(RedisKey.getAgentStatusHashKeyByStatusStr(orgi, pre), agentStatus.getAgentno()); redisCommand.delHashKV(RedisKey.getAgentStatusHashKeyByStatusStr(orgi, pre), agentStatus.getAgentno());
@ -182,9 +178,6 @@ public class Cache {
/** /**
* 获得一个租户的就绪坐席状态 * 获得一个租户的就绪坐席状态
*
* @param orgi
* @return
*/ */
public Map<String, AgentStatus> findAllReadyAgentStatusByOrgi(final String orgi) { public Map<String, AgentStatus> findAllReadyAgentStatusByOrgi(final String orgi) {
List<String> keys = new ArrayList<>(); List<String> keys = new ArrayList<>();
@ -196,9 +189,6 @@ public class Cache {
/** /**
* 获得一个租户的所有坐席状态 * 获得一个租户的所有坐席状态
*
* @param orgi
* @return
*/ */
public Map<String, AgentStatus> findAllAgentStatusByOrgi(final String orgi) { public Map<String, AgentStatus> findAllAgentStatusByOrgi(final String orgi) {
List<String> keys = new ArrayList<>(); List<String> keys = new ArrayList<>();
@ -210,25 +200,8 @@ public class Cache {
return convertFromStringToAgentStatus(map); return convertFromStringToAgentStatus(map);
} }
/**
* Inline方法
*/
private static Map<String, AgentStatus> convertFromStringToAgentStatus(final Map<String, String> map) {
Map<String, AgentStatus> result = new HashMap<String, AgentStatus>();
for (Map.Entry<String, String> entry : map.entrySet()) {
AgentStatus obj = SerializeUtil.deserialize(entry.getValue());
result.put(entry.getKey(), obj);
}
return result;
}
/** /**
* Delete Agent Status * Delete Agent Status
*
* @param agentno
* @param orgi
*/ */
public void deleteAgentStatusByAgentnoAndOrgi(final String agentno, final String orgi) { public void deleteAgentStatusByAgentnoAndOrgi(final String agentno, final String orgi) {
String status = getAgentStatusStatus(agentno, orgi); String status = getAgentStatusStatus(agentno, orgi);
@ -240,10 +213,6 @@ public class Cache {
/** /**
* 获得一个坐席的状态 agentStatus.status * 获得一个坐席的状态 agentStatus.status
* 只返回大类状态 * 只返回大类状态
*
* @param agentno
* @param orgi
* @return
*/ */
private String getAgentStatusStatus(final String agentno, final String orgi) { private String getAgentStatusStatus(final String agentno, final String orgi) {
// 首先判断这个坐席的状态是READY还是BUSY再去更新 // 首先判断这个坐席的状态是READY还是BUSY再去更新
@ -256,24 +225,18 @@ public class Cache {
} }
} }
/** /**
* 获得技能组的坐席状态 * 获得技能组的坐席状态
*
* @param skill
* @param orgi
* @return
*/ */
public List<AgentStatus> getAgentStatusBySkillAndOrgi(final String skill, final String orgi) { public List<AgentStatus> getAgentStatusBySkillAndOrgi(final String skill, final String orgi) {
Map<String, AgentStatus> map = findAllAgentStatusByOrgi(orgi); Map<String, AgentStatus> map = findAllAgentStatusByOrgi(orgi);
List<AgentStatus> agentList = new ArrayList<AgentStatus>(); List<AgentStatus> agentList = new ArrayList<>();
for (Map.Entry<String, AgentStatus> entry : map.entrySet()) { for (Map.Entry<String, AgentStatus> entry : map.entrySet()) {
if (StringUtils.isNotBlank(skill)) { if (StringUtils.isNotBlank(skill)) {
if (entry.getValue().getSkills() != null && if (entry.getValue().getSkills() != null &&
entry.getValue().getSkills().containsKey(skill)) { entry.getValue().getSkills().containsKey(skill)) {
agentList.add(entry.getValue()); agentList.add(entry.getValue());
continue;
} }
} else { } else {
agentList.add(entry.getValue()); agentList.add(entry.getValue());
@ -282,21 +245,18 @@ public class Cache {
return agentList; return agentList;
} }
//**************************
//* AgentUser相关
//**************************
/** /**
* 获得指定租户的就绪的坐席个数 * 获得指定租户的就绪的坐席个数
*
* @param orgi
* @return
*/ */
public int getAgentStatusReadySizeByOrgi(final String orgi) { public int getAgentStatusReadySizeByOrgi(final String orgi) {
return Math.toIntExact(redisCommand.getHashSize(RedisKey.getAgentStatusReadyHashKey(orgi))); return Math.toIntExact(redisCommand.getHashSize(RedisKey.getAgentStatusReadyHashKey(orgi)));
} }
/**************************
* AgentUser相关
**************************/
/** /**
* 更新坐席访客关联关系 * 更新坐席访客关联关系
* TODO 更新坐席的访客列表信息增加新的访客信息 * TODO 更新坐席的访客列表信息增加新的访客信息
@ -305,7 +265,6 @@ public class Cache {
* 但是之前那个关联坐席的信息需要删除要另行维护 * 但是之前那个关联坐席的信息需要删除要另行维护
* *
* @param agentUser 最新的agentUser的状态 * @param agentUser 最新的agentUser的状态
* @param orgi
*/ */
@AgentUserAspect.LinkAgentUser @AgentUserAspect.LinkAgentUser
public void putAgentUserByOrgi(AgentUser agentUser, String orgi) { public void putAgentUserByOrgi(AgentUser agentUser, String orgi) {
@ -335,13 +294,8 @@ public class Cache {
} }
} }
/** /**
* 获得一个客服服务中的访客列表 * 获得一个客服服务中的访客列表
*
* @param agentno
* @param orgi
* @return
*/ */
public List<AgentUser> findInservAgentUsersByAgentnoAndOrgi(final String agentno, final String orgi) { public List<AgentUser> findInservAgentUsersByAgentnoAndOrgi(final String agentno, final String orgi) {
logger.info("[findInservAgentUsersByAgentnoAndOrgi] agentno {}, orgi {}", agentno, orgi); logger.info("[findInservAgentUsersByAgentnoAndOrgi] agentno {}, orgi {}", agentno, orgi);
@ -358,10 +312,6 @@ public class Cache {
/** /**
* 获得一个坐席服务中的访客数量 * 获得一个坐席服务中的访客数量
*
* @param agentno
* @param orgi
* @return
*/ */
public int getInservAgentUsersSizeByAgentnoAndOrgi(final String agentno, final String orgi) { public int getInservAgentUsersSizeByAgentnoAndOrgi(final String agentno, final String orgi) {
return Math.toIntExact(redisCommand.getSetSize(RedisKey.getInServAgentUsersByAgentnoAndOrgi(agentno, orgi))); return Math.toIntExact(redisCommand.getSetSize(RedisKey.getInServAgentUsersByAgentnoAndOrgi(agentno, orgi)));
@ -369,9 +319,6 @@ public class Cache {
/** /**
* 获得服务中的访客的数量 * 获得服务中的访客的数量
*
* @param orgi
* @return
*/ */
public int getInservAgentUsersSizeByOrgi(final String orgi) { public int getInservAgentUsersSizeByOrgi(final String orgi) {
return redisCommand.getHashSize(RedisKey.getAgentUserInServHashKey(orgi)); return redisCommand.getHashSize(RedisKey.getAgentUserInServHashKey(orgi));
@ -379,9 +326,6 @@ public class Cache {
/** /**
* 获得等待中的访客的数量 * 获得等待中的访客的数量
*
* @param orgi
* @return
*/ */
public int getInqueAgentUsersSizeByOrgi(final String orgi) { public int getInqueAgentUsersSizeByOrgi(final String orgi) {
return redisCommand.getHashSize(RedisKey.getAgentUserInQueHashKey(orgi)); return redisCommand.getHashSize(RedisKey.getAgentUserInQueHashKey(orgi));
@ -389,9 +333,6 @@ public class Cache {
/** /**
* Delete agentUser * Delete agentUser
*
* @param agentUser
* @param orgi
*/ */
@AgentUserAspect.LinkAgentUser @AgentUserAspect.LinkAgentUser
public void deleteAgentUserByUserIdAndOrgi(final AgentUser agentUser, String orgi) { public void deleteAgentUserByUserIdAndOrgi(final AgentUser agentUser, String orgi) {
@ -402,9 +343,8 @@ public class Cache {
redisCommand.delHashKV(RedisKey.getAgentUserInServHashKey(orgi), agentUser.getUserid()); redisCommand.delHashKV(RedisKey.getAgentUserInServHashKey(orgi), agentUser.getUserid());
} else if (redisCommand.hasHashKV(RedisKey.getAgentUserEndHashKey(orgi), agentUser.getUserid())) { } else if (redisCommand.hasHashKV(RedisKey.getAgentUserEndHashKey(orgi), agentUser.getUserid())) {
redisCommand.delHashKV(RedisKey.getAgentUserEndHashKey(orgi), agentUser.getUserid()); redisCommand.delHashKV(RedisKey.getAgentUserEndHashKey(orgi), agentUser.getUserid());
} else {
// TODO 考虑是否有其他状态保存
} }
// TODO 考虑是否有其他状态保存
} }
/*************************** /***************************
@ -425,20 +365,17 @@ public class Cache {
} }
} }
public void deleteConsultInviteBySnsidAndOrgi(final String snsid, final String orgi) {
redisCommand.delHashKV(RedisKey.getConsultInvitesByOrgi(orgi), snsid);
}
/**************************** /****************************
* OnlineUser相关 * OnlineUser相关
****************************/ ****************************/
public void deleteConsultInviteBySnsidAndOrgi(final String snsid, final String orgi) {
redisCommand.delHashKV(RedisKey.getConsultInvitesByOrgi(orgi), snsid);
}
/** /**
* 更新 onlineUser * 更新 onlineUser
*
* @param onlineUser
* @param orgi
*/ */
public void putOnlineUserByOrgi(final OnlineUser onlineUser, final String orgi) { public void putOnlineUserByOrgi(final OnlineUser onlineUser, final String orgi) {
// 此处onlineUser的id onlineUser userId相同 // 此处onlineUser的id onlineUser userId相同
@ -448,10 +385,6 @@ public class Cache {
/** /**
* 获得 onlineUser * 获得 onlineUser
*
* @param id
* @param orgi
* @return
*/ */
public OnlineUser findOneOnlineUserByUserIdAndOrgi(final String id, final String orgi) { public OnlineUser findOneOnlineUserByUserIdAndOrgi(final String id, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getOnlineUserHashKey(orgi), id); String serialized = redisCommand.getHashKV(RedisKey.getOnlineUserHashKey(orgi), id);
@ -463,16 +396,8 @@ public class Cache {
} }
} }
private static OnlineUser convertFromStringToOnlineUser(final String serialized) {
OnlineUser obj = SerializeUtil.deserialize(serialized);
return obj;
}
/** /**
* 删除 onlineUser * 删除 onlineUser
*
* @param id
* @param orgi
*/ */
public void deleteOnlineUserByIdAndOrgi(final String id, final String orgi) { public void deleteOnlineUserByIdAndOrgi(final String id, final String orgi) {
redisCommand.delHashKV(RedisKey.getOnlineUserHashKey(orgi), id); redisCommand.delHashKV(RedisKey.getOnlineUserHashKey(orgi), id);
@ -480,8 +405,6 @@ public class Cache {
/** /**
* 根据租户ID获得在线访客的列表大小 * 根据租户ID获得在线访客的列表大小
*
* @param orgi
*/ */
public int getOnlineUserSizeByOrgi(final String orgi) { public int getOnlineUserSizeByOrgi(final String orgi) {
return redisCommand.getHashSize(RedisKey.getOnlineUserHashKey(orgi)); return redisCommand.getHashSize(RedisKey.getOnlineUserHashKey(orgi));
@ -490,10 +413,6 @@ public class Cache {
/** /**
* 将在线访客从一个坐席的服务列表中删除 * 将在线访客从一个坐席的服务列表中删除
*
* @param userid
* @param agentno
* @param orgi
*/ */
public void deleteOnlineUserIdFromAgentStatusByUseridAndAgentnoAndOrgi(final String userid, final String agentno, final String orgi) { public void deleteOnlineUserIdFromAgentStatusByUseridAndAgentnoAndOrgi(final String userid, final String agentno, final String orgi) {
redisCommand.removeSetVal(RedisKey.getInServAgentUsersByAgentnoAndOrgi(agentno, orgi), userid); redisCommand.removeSetVal(RedisKey.getInServAgentUsersByAgentnoAndOrgi(agentno, orgi), userid);
@ -509,16 +428,12 @@ public class Cache {
} }
/****************************** //******************************
* Callcenter Agent 相关 //* Callcenter Agent 相关
******************************/ //******************************
/** /**
* 更新CallCenterAgent * 更新CallCenterAgent
*
* @param id
* @param orgi
* @param agent
*/ */
public void putCallCenterAgentByIdAndOrgi(final String id, final String orgi, final CallCenterAgent agent) { public void putCallCenterAgentByIdAndOrgi(final String id, final String orgi, final CallCenterAgent agent) {
redisCommand.setHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id, SerializeUtil.serialize(agent)); redisCommand.setHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id, SerializeUtil.serialize(agent));
@ -526,10 +441,6 @@ public class Cache {
/** /**
* 根据ID和租户ID获得CallCenterAgent * 根据ID和租户ID获得CallCenterAgent
*
* @param id
* @param orgi
* @return
*/ */
public CallCenterAgent findOneCallCenterAgentByIdAndOrgi(final String id, final String orgi) { public CallCenterAgent findOneCallCenterAgentByIdAndOrgi(final String id, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id); String serialized = redisCommand.getHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id);
@ -542,9 +453,6 @@ public class Cache {
/** /**
* 删除CallCenterAgent * 删除CallCenterAgent
*
* @param id
* @param orgi
*/ */
public void deleteCallCenterAgentByIdAndOrgi(final String id, final String orgi) { public void deleteCallCenterAgentByIdAndOrgi(final String id, final String orgi) {
redisCommand.delHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id); redisCommand.delHashKV(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi), id);
@ -553,9 +461,6 @@ public class Cache {
/** /**
* 根据租户ID获得所有的CallCenterAgent * 根据租户ID获得所有的CallCenterAgent
*
* @param orgi
* @return
*/ */
public Map<String, CallCenterAgent> findAllCallCenterAgentsByOrgi(final String orgi) { public Map<String, CallCenterAgent> findAllCallCenterAgentsByOrgi(final String orgi) {
Map<String, String> map = redisCommand.getHash(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi)); Map<String, String> map = redisCommand.getHash(RedisKey.getCallCenterAgentHashKeyByOrgi(orgi));
@ -654,6 +559,7 @@ public class Cache {
public List<SysDic> getSysDicItemsByCodeAndOrgi(final String code, final String orgi) { public List<SysDic> getSysDicItemsByCodeAndOrgi(final String code, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getSysDicHashKeyByOrgi(orgi), code); String serialized = redisCommand.getHashKV(RedisKey.getSysDicHashKeyByOrgi(orgi), code);
if (serialized != null) { if (serialized != null) {
//noinspection unchecked
return (List<SysDic>) SerializeUtil.deserialize(serialized); return (List<SysDic>) SerializeUtil.deserialize(serialized);
} }
return null; return null;
@ -724,6 +630,7 @@ public class Cache {
public <T extends Serializable> T findOneSystemByIdAndOrgi(final String id, final String orgi) { public <T extends Serializable> T findOneSystemByIdAndOrgi(final String id, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id); String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id);
if (StringUtils.isNotBlank(serialized)) { if (StringUtils.isNotBlank(serialized)) {
//noinspection unchecked
return (T) SerializeUtil.deserialize(serialized); return (T) SerializeUtil.deserialize(serialized);
} }
return null; return null;
@ -732,6 +639,7 @@ public class Cache {
public <T extends Serializable> List<T> findOneSystemListByIdAndOrgi(final String id, final String orgi) { public <T extends Serializable> List<T> findOneSystemListByIdAndOrgi(final String id, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id); String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id);
if (StringUtils.isNotBlank(serialized)) { if (StringUtils.isNotBlank(serialized)) {
//noinspection unchecked
return (List<T>) SerializeUtil.deserialize(serialized); return (List<T>) SerializeUtil.deserialize(serialized);
} }
return null; return null;
@ -740,6 +648,7 @@ public class Cache {
public <TK, TV extends Serializable> Map<TK, TV> findOneSystemMapByIdAndOrgi(final String id, final String orgi) { public <TK, TV extends Serializable> Map<TK, TV> findOneSystemMapByIdAndOrgi(final String id, final String orgi) {
String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id); String serialized = redisCommand.getHashKV(RedisKey.getSystemHashKeyByOrgi(orgi), id);
if (StringUtils.isNotBlank(serialized)) { if (StringUtils.isNotBlank(serialized)) {
//noinspection unchecked
return (Map<TK, TV>) SerializeUtil.deserialize(serialized); return (Map<TK, TV>) SerializeUtil.deserialize(serialized);
} }
return null; return null;
@ -781,6 +690,7 @@ public class Cache {
public List<SessionConfig> findOneSessionConfigListByOrgi(final String orgi) { public List<SessionConfig> findOneSessionConfigListByOrgi(final String orgi) {
String serialized = redisCommand.get(RedisKey.getSessionConfigList(orgi)); String serialized = redisCommand.get(RedisKey.getSessionConfigList(orgi));
if (StringUtils.isNotBlank(serialized)) { if (StringUtils.isNotBlank(serialized)) {
//noinspection unchecked
return (List<SessionConfig>) SerializeUtil.deserialize(serialized); return (List<SessionConfig>) SerializeUtil.deserialize(serialized);
} }
@ -816,7 +726,7 @@ public class Cache {
if (StringUtils.isBlank(serialized)) { if (StringUtils.isBlank(serialized)) {
return Optional.empty(); return Optional.empty();
} }
return Optional.ofNullable((AgentUserAudit) SerializeUtil.deserialize(serialized)); return Optional.ofNullable(SerializeUtil.deserialize(serialized));
} }
public boolean existAgentUserAuditByOrgiAndId(final String orgi, final String agentUserId) { public boolean existAgentUserAuditByOrgiAndId(final String orgi, final String agentUserId) {
@ -824,16 +734,13 @@ public class Cache {
} }
/****************************************** //******************************************
* User Session 相关 //* User Session 相关
******************************************/ //******************************************
/** /**
* 存入user的session存储这组信息是为了让客户的账号只能在一个浏览器内登录使用 * 存入user的session存储这组信息是为了让客户的账号只能在一个浏览器内登录使用
* 如果一个用户账号在多个浏览器使用则登出之前的登录只保留最后一个登录正常使用 * 如果一个用户账号在多个浏览器使用则登出之前的登录只保留最后一个登录正常使用
*
* @param agentno
* @param sessionId
* @param orgi
*/ */
public void putUserSessionByAgentnoAndSessionIdAndOrgi(final String agentno, final String sessionId, final String orgi) { public void putUserSessionByAgentnoAndSessionIdAndOrgi(final String agentno, final String sessionId, final String orgi) {
redisCommand.setHashKV(RedisKey.getUserSessionKeyByOrgi(orgi), agentno, sessionId); redisCommand.setHashKV(RedisKey.getUserSessionKeyByOrgi(orgi), agentno, sessionId);

View File

@ -1,388 +1,363 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.controller.api; package com.chatopera.cc.controller.api;
import com.chatopera.cc.acd.ACDAgentDispatcher; import com.chatopera.cc.acd.ACDAgentDispatcher;
import com.chatopera.cc.acd.ACDAgentService; import com.chatopera.cc.acd.ACDAgentService;
import com.chatopera.cc.acd.basic.ACDComposeContext; import com.chatopera.cc.acd.basic.ACDComposeContext;
import com.chatopera.cc.acd.basic.ACDMessageHelper; import com.chatopera.cc.acd.basic.ACDMessageHelper;
import com.chatopera.cc.basic.MainContext.*; import com.chatopera.cc.basic.MainContext.*;
import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.cache.Cache; import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.controller.Handler; import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.controller.api.request.RestUtils; import com.chatopera.cc.controller.api.request.RestUtils;
import com.chatopera.cc.exception.CSKefuException; import com.chatopera.cc.exception.CSKefuException;
import com.chatopera.cc.model.*; import com.chatopera.cc.model.*;
import com.chatopera.cc.peer.PeerSyncIM; import com.chatopera.cc.peer.PeerSyncIM;
import com.chatopera.cc.persistence.repository.AgentServiceRepository; import com.chatopera.cc.persistence.repository.AgentServiceRepository;
import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.AgentUserRepository;
import com.chatopera.cc.persistence.repository.UserRepository; import com.chatopera.cc.persistence.repository.UserRepository;
import com.chatopera.cc.proxy.AgentUserProxy; import com.chatopera.cc.proxy.AgentUserProxy;
import com.chatopera.cc.socketio.message.Message; import com.chatopera.cc.socketio.message.Message;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.apache.commons.lang.StringUtils; import lombok.RequiredArgsConstructor;
import org.slf4j.Logger; import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import javax.validation.Valid;
import java.util.List; import java.util.Date;
import java.util.List;
/**
* ACD服务 获取当前对话中的访客 /**
*/ * ACD服务 获取当前对话中的访客
@RestController */
@RequestMapping("/api/agentuser") @RestController
public class ApiAgentUserController extends Handler { @RequestMapping("/api/agentuser")
@RequiredArgsConstructor
private final static Logger logger = LoggerFactory.getLogger(ApiAgentUserController.class); public class ApiAgentUserController extends Handler {
@Autowired private final static Logger logger = LoggerFactory.getLogger(ApiAgentUserController.class);
private ACDMessageHelper acdMessageHelper;
@org.springframework.lang.NonNull
@Autowired private final ACDMessageHelper acdMessageHelper;
private AgentUserProxy agentUserProxy;
@org.springframework.lang.NonNull
@Autowired private final AgentUserProxy agentUserProxy;
private ACDAgentService acdAgentService;
@org.springframework.lang.NonNull
@Autowired private final ACDAgentService acdAgentService;
private Cache cache;
@org.springframework.lang.NonNull
@Autowired private final Cache cache;
private PeerSyncIM peerSyncIM;
@org.springframework.lang.NonNull
@Autowired private final PeerSyncIM peerSyncIM;
private AgentUserRepository agentUserRes;
@org.springframework.lang.NonNull
@Autowired private final AgentUserRepository agentUserRes;
private UserRepository userRes;
@org.springframework.lang.NonNull
@Autowired private final UserRepository userRes;
private AgentServiceRepository agentServiceRes;
@org.springframework.lang.NonNull
@Autowired private final AgentServiceRepository agentServiceRes;
private ACDAgentDispatcher acdAgentDispatcher;
@org.springframework.lang.NonNull
/** private final ACDAgentDispatcher acdAgentDispatcher;
* 获取当前对话中的访客
* 坐席相关 RestAPI /**
* * 获取当前对话中的访客
* @param request * 坐席相关 RestAPI
* @return */
*/ @RequestMapping(method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.POST) @Menu(type = "apps", subtype = "agentuser", access = true)
@Menu(type = "apps", subtype = "agentuser", access = true) public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body, @Valid String q) {
public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body, @Valid String q) { logger.info("[operations] body {}, q {}", body, q);
logger.info("[operations] body {}, q {}", body, q); final JsonObject j = StringUtils.isBlank(body) ? new JsonObject() : JsonParser.parseString(body).getAsJsonObject();
final JsonObject j = StringUtils.isBlank(body) ? (new JsonObject()) : (new JsonParser()).parse( JsonObject json = new JsonObject();
body).getAsJsonObject(); HttpHeaders headers = RestUtils.header();
JsonObject json = new JsonObject();
HttpHeaders headers = RestUtils.header(); if (!j.has("ops")) {
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_1);
if (!j.has("ops")) { json.addProperty(RestUtils.RESP_KEY_ERROR, "不合法的请求参数。");
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_1); } else {
json.addProperty(RestUtils.RESP_KEY_ERROR, "不合法的请求参数。"); switch (StringUtils.lowerCase(j.get("ops").getAsString())) {
} else { case "inserv":
switch (StringUtils.lowerCase(j.get("ops").getAsString())) { json = inserv(request);
case "inserv": break;
json = inserv(request, j); case "withdraw":
break; json = withdraw(request);
case "withdraw": break;
json = withdraw(request, j); case "end":
break; json = end(request, j);
case "end": break;
json = end(request, j); case "transout":
break; json = transout(request, j);
case "transout": break;
json = transout(request, j); default:
break; json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_2);
default: json.addProperty(RestUtils.RESP_KEY_ERROR, "不合法的操作。");
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_2); }
json.addProperty(RestUtils.RESP_KEY_ERROR, "不合法的操作。"); }
}
} return new ResponseEntity<>(json.toString(), headers, HttpStatus.OK);
}
return new ResponseEntity<String>(json.toString(), headers, HttpStatus.OK);
} /**
* 执行坐席转接
/** * 将会话转接给别人
* 执行坐席转接 */
* 将会话转接给别人 private JsonObject transout(final HttpServletRequest request, final JsonObject payload) {
* logger.info("[transout] payload {}", payload.toString());
* @param request final String orgi = super.getOrgi(request);
* @param payload final User logined = super.getUser(request);
* @return JsonObject resp = new JsonObject();
*/
private JsonObject transout(final HttpServletRequest request, final JsonObject payload) { /*
logger.info("[transout] payload ", payload.toString()); * 必填参数
final String orgi = super.getOrgi(request); */
final User logined = super.getUser(request); // 目标坐席
JsonObject resp = new JsonObject(); final String transAgentId = payload.get("agentno").getAsString();
// 当前会话的ID
/** final String agentUserId = payload.get("agentUserId").getAsString();
* 必填参数 // 坐席服务ID
*/ final String agentServiceId = payload.get("agentServiceId").getAsString();
// 目标坐席
final String transAgentId = payload.get("agentno").getAsString(); if (StringUtils.isNotBlank(agentUserId) &&
// 当前会话的ID StringUtils.isNotBlank(transAgentId) &&
final String agentUserId = payload.get("agentUserId").getAsString(); StringUtils.isNotBlank(agentServiceId)) {
// 坐席服务ID final User targetAgent = userRes.findById(transAgentId)
final String agentServiceId = payload.get("agentServiceId").getAsString(); .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Agent %s not found", transAgentId)));
final AgentService agentService = agentServiceRes.findByIdAndOrgi(agentServiceId, orgi);
if (StringUtils.isNotBlank(agentUserId) &&
StringUtils.isNotBlank(transAgentId) && /*
StringUtils.isNotBlank(agentServiceId)) { * 更新AgentUser
final User targetAgent = userRes.findOne(transAgentId); */
final AgentService agentService = agentServiceRes.findByIdAndOrgi(agentServiceId, orgi); final AgentUser agentUser = agentUserProxy.findOne(agentUserId).orElse(null);
if (agentUser != null) {
/** final AgentUserAudit agentAudits = cache.findOneAgentUserAuditByOrgiAndId(orgi, agentUserId).orElse(null);
* 更新AgentUser
*/ // 当前服务于访客的坐席
final AgentUser agentUser = agentUserProxy.findOne(agentUserId).orElseGet(null); final String currentAgentno = agentUser.getAgentno();
if (agentUser != null) { // 当前访客的ID
final AgentUserAudit agentAudits = cache.findOneAgentUserAuditByOrgiAndId(orgi, agentUserId).orElseGet( final String userId = agentUser.getUserid();
null);
logger.info(
// 当前服务于访客的坐席 "[transout] agentuserid {} \n target agent id {}, \n current agent id {}, onlineuserid {}",
final String currentAgentno = agentUser.getAgentno(); agentUserId, transAgentId, currentAgentno, userId);
// 当前访客的ID
final String userId = agentUser.getUserid();
// 检查权限
logger.info( if ((!logined.isAdmin()) && (!StringUtils.equals(
"[transout] agentuserid {} \n target agent id {}, \n current agent id {}, onlineuserid {}", agentUser.getAgentno(),
agentUserId, transAgentId, currentAgentno, userId); logined.getId())) && (!isTransPermissionAllowed(
agentAudits, logined))) {
// 1. 不是超级用户2. 也是不是会话的所有者; 3. 也不是坐席监控人员
// 检查权限 logger.info("[end] Permission not fulfill.");
if ((!logined.isAdmin()) && (!StringUtils.equals( resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3);
agentUser.getAgentno(), resp.addProperty(RestUtils.RESP_KEY_ERROR, "Permission denied.");
logined.getId())) && (!isTransPermissionAllowed( return resp;
agentAudits, logined))) { }
// 1. 不是超级用户2. 也是不是会话的所有者; 3. 也不是坐席监控人员
logger.info("[end] Permission not fulfill."); agentUser.setAgentno(transAgentId);
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3); agentUser.setAgentname(targetAgent.getUname());
resp.addProperty(RestUtils.RESP_KEY_ERROR, "Permission denied."); agentUserRes.save(agentUser);
return resp;
} /*
* 坐席状态
agentUser.setAgentno(transAgentId); */
agentUser.setAgentname(targetAgent.getUname()); // 转接目标坐席
agentUserRes.save(agentUser); final AgentStatus transAgentStatus = cache.findOneAgentStatusByAgentnoAndOrig(transAgentId, orgi);
/** // 转接源坐席
* 坐席状态 final AgentStatus currentAgentStatus = cache.findOneAgentStatusByAgentnoAndOrig(currentAgentno, orgi);
*/
// 转接目标坐席 if (StringUtils.equals(
final AgentStatus transAgentStatus = cache.findOneAgentStatusByAgentnoAndOrig(transAgentId, orgi); AgentUserStatusEnum.INSERVICE.toString(),
agentUser.getStatus())) { //转接 发送消息给 目标坐席
// 转接源坐席 // 更新当前坐席的服务访客列表
final AgentStatus currentAgentStatus = cache.findOneAgentStatusByAgentnoAndOrig(currentAgentno, orgi); if (currentAgentStatus != null) {
cache.deleteOnlineUserIdFromAgentStatusByUseridAndAgentnoAndOrgi(userId, currentAgentno, orgi);
if (StringUtils.equals( agentUserProxy.updateAgentStatus(currentAgentStatus, orgi);
AgentUserStatusEnum.INSERVICE.toString(), }
agentUser.getStatus())) { //转接 发送消息给 目标坐席
// 更新当前坐席的服务访客列表 if (transAgentStatus != null) {
if (currentAgentStatus != null) { agentService.setAgentno(transAgentId);
cache.deleteOnlineUserIdFromAgentStatusByUseridAndAgentnoAndOrgi(userId, currentAgentno, orgi); agentService.setAgentusername(transAgentStatus.getUsername());
agentUserProxy.updateAgentStatus(currentAgentStatus, orgi); }
}
// 转接坐席提示消息
if (transAgentStatus != null) { Message outMessage = new Message();
agentService.setAgentno(transAgentId); outMessage.setMessage(
agentService.setAgentusername(transAgentStatus.getUsername()); acdMessageHelper.getSuccessMessage(agentService, agentUser.getChannel(), orgi));
} outMessage.setMessageType(MediaType.TEXT.toString());
outMessage.setCalltype(CallType.IN.toString());
// 转接坐席提示消息 outMessage.setCreatetime(MainUtils.dateFormate.format(new Date()));
Message outMessage = new Message(); outMessage.setAgentUser(agentUser);
outMessage.setMessage( outMessage.setAgentService(agentService);
acdMessageHelper.getSuccessMessage(agentService, agentUser.getChannel(), orgi));
outMessage.setMessageType(MediaType.TEXT.toString()); if (StringUtils.isNotBlank(agentUser.getUserid())) {
outMessage.setCalltype(CallType.IN.toString()); peerSyncIM.send(
outMessage.setCreatetime(MainUtils.dateFormate.format(new Date())); ReceiverType.VISITOR,
outMessage.setAgentUser(agentUser); ChannelType.toValue(agentUser.getChannel()),
outMessage.setAgentService(agentService); agentUser.getAppid(),
MessageType.STATUS,
if (StringUtils.isNotBlank(agentUser.getUserid())) { agentUser.getUserid(),
peerSyncIM.send( outMessage,
ReceiverType.VISITOR, true);
ChannelType.toValue(agentUser.getChannel()), }
agentUser.getAppid(),
MessageType.STATUS, // 通知转接消息给新坐席
agentUser.getUserid(), outMessage.setChannelMessage(agentUser);
outMessage, outMessage.setAgentUser(agentUser);
true); peerSyncIM.send(
} ReceiverType.AGENT, ChannelType.WEBIM,
agentUser.getAppid(), MessageType.NEW, agentService.getAgentno(),
// 通知转接消息给新坐席 outMessage, true);
outMessage.setChannelMessage(agentUser);
outMessage.setAgentUser(agentUser); // 通知消息给前坐席
peerSyncIM.send( if (!StringUtils.equals(logined.getId(), currentAgentno)) {
ReceiverType.AGENT, ChannelType.WEBIM, // 如果当前坐席不是登录用户因为登录用户会从RestAPI返回转接的结果
agentUser.getAppid(), MessageType.NEW, agentService.getAgentno(), // 该登录用户可能是坐席监控或当前坐席那么如果是坐席监控就有必要
outMessage, true); // 通知前坐席这个事件
peerSyncIM.send(ReceiverType.AGENT, ChannelType.WEBIM, agentUser.getAppid(),
// 通知消息给前坐席 MessageType.TRANSOUT,
if (!StringUtils.equals(logined.getId(), currentAgentno)) { currentAgentno, outMessage, true);
// 如果当前坐席不是登录用户因为登录用户会从RestAPI返回转接的结果 }
// 该登录用户可能是坐席监控或当前坐席那么如果是坐席监控就有必要 }
// 通知前坐席这个事件
peerSyncIM.send(ReceiverType.AGENT, ChannelType.WEBIM, agentUser.getAppid(), if (agentService != null) {
MessageType.TRANSOUT, agentService.setAgentno(transAgentId);
currentAgentno, outMessage, true); if (payload.has("memo") && StringUtils.isNotBlank(payload.get("memo").getAsString())) {
} agentService.setTransmemo(payload.get("memo").getAsString());
} }
agentService.setTrans(true);
if (agentService != null) { agentService.setTranstime(new Date());
agentService.setAgentno(transAgentId); agentServiceRes.save(agentService);
if (payload.has("memo") && StringUtils.isNotBlank(payload.get("memo").getAsString())) { }
agentService.setTransmemo(payload.get("memo").getAsString());
} resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
agentService.setTrans(true); resp.addProperty(RestUtils.RESP_KEY_DATA, "success");
agentService.setTranstime(new Date()); } else {
agentServiceRes.save(agentService); resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_4);
} resp.addProperty(RestUtils.RESP_KEY_ERROR, "Can not find agent user.");
}
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC); } else {
resp.addProperty(RestUtils.RESP_KEY_DATA, "success"); resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_5);
} else { resp.addProperty(RestUtils.RESP_KEY_ERROR, "Invalid params.");
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_4); }
resp.addProperty(RestUtils.RESP_KEY_ERROR, "Can not find agent user.");
} return resp;
} else { }
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_5);
resp.addProperty(RestUtils.RESP_KEY_ERROR, "Invalid params."); /**
} * 结束对话
* 如果当前对话属于登录用户或登录用户为超级用户则可以结束这个对话
return resp; */
} private JsonObject end(final HttpServletRequest request, final JsonObject payload) {
logger.info("[end] payload {}", payload.toString());
/** final String orgi = super.getOrgi(request);
* 结束对话 final User logined = super.getUser(request);
* 如果当前对话属于登录用户或登录用户为超级用户则可以结束这个对话 JsonObject resp = new JsonObject();
*
* @param request final AgentUser agentUser = agentUserRes.findByIdAndOrgi(payload.get("id").getAsString(), orgi);
* @param payload if (agentUser != null) {
* @return if ((StringUtils.equals(
*/ logined.getId(), agentUser.getAgentno()) || logined.isAdmin())) {
private JsonObject end(final HttpServletRequest request, final JsonObject payload) { // 删除访客-坐席关联关系包括缓存
logger.info("[end] payload {}", payload.toString()); try {
final String orgi = super.getOrgi(request); acdAgentService.finishAgentUser(agentUser, orgi);
final User logined = super.getUser(request); } catch (CSKefuException e) {
JsonObject resp = new JsonObject(); // 未能删除成功
logger.error("[end]", e);
final AgentUser agentUser = agentUserRes.findByIdAndOrgi(payload.get("id").getAsString(), orgi); }
if (agentUser != null) { resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
if ((StringUtils.equals( resp.addProperty(RestUtils.RESP_KEY_DATA, "success");
logined.getId(), agentUser.getAgentno()) || logined.isAdmin())) { } else {
// 删除访客-坐席关联关系包括缓存 logger.info("[end] Permission not fulfill.");
try { resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3);
acdAgentService.finishAgentUser(agentUser, orgi); resp.addProperty(RestUtils.RESP_KEY_ERROR, "Permission denied.");
} catch (CSKefuException e) { }
// 未能删除成功 } else {
logger.error("[end]", e); resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_4);
} resp.addProperty(RestUtils.RESP_KEY_ERROR, "Agent User not found.");
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC); }
resp.addProperty(RestUtils.RESP_KEY_DATA, "success");
} else { return resp;
logger.info("[end] Permission not fulfill."); }
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3);
resp.addProperty(RestUtils.RESP_KEY_ERROR, "Permission denied."); /**
} * 撤退一个坐席
} else { * 将当前坐席服务中的访客分配给其他就绪的坐席
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_4); */
resp.addProperty(RestUtils.RESP_KEY_ERROR, "Agent User not found."); private JsonObject withdraw(final HttpServletRequest request) {
} JsonObject resp = new JsonObject();
ACDComposeContext ctx = new ACDComposeContext();
return resp; ctx.setAgentno(super.getUser(request).getId());
} ctx.setOrgi(super.getOrgi(request));
acdAgentDispatcher.dequeue(ctx);
/** resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
* 撤退一个坐席 return resp;
* 将当前坐席服务中的访客分配给其他就绪的坐席 }
*
* @param request
* @param j /**
* @return * 获得当前访客服务中的访客信息
*/ * 获取当前正在对话的访客信息包含多种渠道来源的访客
private JsonObject withdraw(final HttpServletRequest request, final JsonObject j) { */
JsonObject resp = new JsonObject(); private JsonObject inserv(final HttpServletRequest request) {
ACDComposeContext ctx = new ACDComposeContext(); JsonObject resp = new JsonObject();
ctx.setAgentno(super.getUser(request).getId()); JsonArray data = new JsonArray();
ctx.setOrgi(super.getOrgi(request));
acdAgentDispatcher.dequeue(ctx); List<AgentUser> lis = cache.findInservAgentUsersByAgentnoAndOrgi(
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC); super.getUser(request).getId(), super.getOrgi(request));
return resp; for (final AgentUser au : lis) {
} JsonObject obj = new JsonObject();
obj.addProperty("id", au.getId());
obj.addProperty("userid", au.getUserid());
/** obj.addProperty("status", au.getStatus());
* 获得当前访客服务中的访客信息 obj.addProperty("agentno", au.getAgentno());
* 获取当前正在对话的访客信息包含多种渠道来源的访客 obj.addProperty("channel", au.getChannel());
* obj.addProperty("nickname", au.getNickname());
* @param request data.add(obj);
* @param j }
* @return resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
*/ resp.add("data", data);
private JsonObject inserv(final HttpServletRequest request, final JsonObject j) {
JsonObject resp = new JsonObject(); return resp;
JsonArray data = new JsonArray(); }
List<AgentUser> lis = cache.findInservAgentUsersByAgentnoAndOrgi( /**
super.getUser(request).getId(), super.getOrgi(request)); * 检查是否具备该会话的坐席监控权限
for (final AgentUser au : lis) { */
JsonObject obj = new JsonObject(); private boolean isTransPermissionAllowed(final AgentUserAudit agentUserAudit, final User user) {
obj.addProperty("id", au.getId()); return agentUserAudit != null && agentUserAudit.getSubscribers().containsKey(user.getId());
obj.addProperty("userid", au.getUserid()); }
obj.addProperty("status", au.getStatus()); }
obj.addProperty("agentno", au.getAgentno());
obj.addProperty("channel", au.getChannel());
obj.addProperty("nickname", au.getNickname());
data.add(obj);
}
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
resp.add("data", data);
return resp;
}
/**
* 检查是否具备该会话的坐席监控权限
*
* @param agentUserAudit
* @param user
* @return
*/
private boolean isTransPermissionAllowed(final AgentUserAudit agentUserAudit, final User user) {
if (agentUserAudit != null && agentUserAudit.getSubscribers().containsKey(user.getId())) {
return true;
}
return false;
}
}

View File

@ -618,7 +618,7 @@ public class AgentAuditController extends Handler {
payload.put("orgi", orgi); payload.put("orgi", orgi);
ModelAndView view = end(request, agentuserid); ModelAndView view = end(request, agentuserid);
// 更新或创建黑名单 // 更新或创建黑名单
blackEntityProxy.updateOrCreateBlackEntity(blackEntity, logined, userid, orgi, agentserviceid, agentuserid); blackEntityProxy.updateOrCreateBlackEntity(blackEntity, logined, userid, orgi, agentserviceid);
// 创建定时任务 取消拉黑 // 创建定时任务 取消拉黑
brokerPublisher.send( brokerPublisher.send(

View File

@ -748,7 +748,7 @@
ModelAndView view = end(request, agentuserid); ModelAndView view = end(request, agentuserid);
// 更新或创建黑名单 // 更新或创建黑名单
blackEntityProxy.updateOrCreateBlackEntity(blackEntity, logined, userid, orgi, agentserviceid, agentuserid); blackEntityProxy.updateOrCreateBlackEntity(blackEntity, logined, userid, orgi, agentserviceid);
// 创建定时任务 取消拉黑 // 创建定时任务 取消拉黑
brokerPublisher.send( brokerPublisher.send(

View File

@ -1,285 +1,286 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.controller.apps; package com.chatopera.cc.controller.apps;
import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.cache.Cache; import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.controller.Handler; import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.*; import com.chatopera.cc.model.*;
import com.chatopera.cc.persistence.repository.*; import com.chatopera.cc.persistence.repository.*;
import com.chatopera.cc.proxy.OnlineUserProxy; import com.chatopera.cc.proxy.OnlineUserProxy;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import org.apache.commons.lang.StringUtils; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.lang.NonNull;
import org.springframework.ui.ModelMap; import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.servlet.http.HttpServletRequest;
import java.io.File; import javax.validation.Valid;
import java.io.IOException; import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.IOException;
import java.net.URLDecoder; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLDecoder;
import java.security.NoSuchAlgorithmException; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@Controller @Controller
@RequestMapping("/apps/tenant") @RequestMapping("/apps/tenant")
public class TenantController extends Handler { @RequiredArgsConstructor
public class TenantController extends Handler {
@Autowired
private TenantRepository tenantRes; @NonNull
private final TenantRepository tenantRes;
@Autowired
private OrgiSkillRelRepository orgiSkillRelRes; @NonNull
private final OrgiSkillRelRepository orgiSkillRelRes;
@Autowired
private OrganRepository organRes; @NonNull
private final OrganRepository organRes;
@Autowired
private OrganizationRepository organizationRes; @NonNull
private final OrganizationRepository organizationRes;
@Autowired
private AgentUserRepository agentUserRepository; @NonNull
private final AgentUserRepository agentUserRepository;
@Autowired
private Cache cache; @NonNull
private final Cache cache;
@Value("${web.upload-path}")
private String path; @Value("${web.upload-path}")
private String path;
@RequestMapping("/index")
@Menu(type = "apps", subtype = "tenant") @RequestMapping("/index")
public ModelAndView index( @Menu(type = "apps", subtype = "tenant")
ModelMap map, final HttpServletRequest request, public ModelAndView index(
final @Valid String msg, ModelMap map, final HttpServletRequest request,
final @Valid String currentorgi, final @Valid String msg,
final @Valid String currentname) throws IOException { final @Valid String currentorgi,
if (super.isEnabletneant()) { final @Valid String currentname) throws IOException {
// 系统管理员开启多租户访问 if (super.isEnabletneant()) {
if (super.getUser(request).isAdmin()) { // 系统管理员开启多租户访问
map.addAttribute("tenantList", tenantRes.findByOrgid(super.getOrgid(request))); if (super.getUser(request).isAdmin()) {
} else { map.addAttribute("tenantList", tenantRes.findByOrgid(super.getOrgid(request)));
List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findBySkillidIn( } else {
new ArrayList<>((super.getUser(request)).getAffiliates())); List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findBySkillidIn(
List<Tenant> tenantList = null; new ArrayList<>((super.getUser(request)).getAffiliates()));
if (!orgiSkillRelList.isEmpty()) { List<Tenant> tenantList = null;
tenantList = new ArrayList<Tenant>(); if (!orgiSkillRelList.isEmpty()) {
for (OrgiSkillRel orgiSkillRel : orgiSkillRelList) { tenantList = new ArrayList<>();
Tenant t = tenantRes.findById(orgiSkillRel.getOrgi()); for (OrgiSkillRel orgiSkillRel : orgiSkillRelList) {
if (t != null) { Tenant t = tenantRes.findById(orgiSkillRel.getOrgi());
tenantList.add(t); if (t != null) {
} tenantList.add(t);
} }
} }
map.addAttribute("tenantList", tenantList); }
} map.addAttribute("tenantList", tenantList);
} else { }
map.addAttribute("tenantList", tenantRes.findById(super.getOrgi(request))); } else {
} map.addAttribute("tenantList", tenantRes.findById(super.getOrgi(request)));
map.addAttribute("organization", organizationRes.findById(super.getUser(request).getOrgid())); }
map.addAttribute("msg", msg); map.addAttribute("organization", organizationRes.findById(super.getUser(request).getOrgid()));
map.addAttribute("currentorgi", currentorgi); map.addAttribute("msg", msg);
if (currentname != null) { map.addAttribute("currentorgi", currentorgi);
map.addAttribute("currentname", URLDecoder.decode(currentname, "UTF-8")); if (currentname != null) {
} map.addAttribute("currentname", URLDecoder.decode(currentname, "UTF-8"));
return request(super.createRequestPageTempletResponse("/apps/tenant/index")); }
} return request(super.createRequestPageTempletResponse("/apps/tenant/index"));
}
@RequestMapping("/add")
@Menu(type = "apps", subtype = "tenant") @RequestMapping("/add")
public ModelAndView add(ModelMap map, HttpServletRequest request) { @Menu(type = "apps", subtype = "tenant")
if (super.isTenantshare()) { public ModelAndView add(ModelMap map, HttpServletRequest request) {
map.addAttribute("isShowSkillGroups", true); if (super.isTenantshare()) {
List<Organ> organList = organRes.findByOrgiAndOrgid( map.addAttribute("isShowSkillGroups", true);
super.getOrgiByTenantshare(request), super.getOrgid(request)); List<Organ> organList = organRes.findByOrgiAndOrgid(
map.addAttribute("skillGroups", organList); super.getOrgiByTenantshare(request), super.getOrgid(request));
} map.addAttribute("skillGroups", organList);
return request(super.createRequestPageTempletResponse("/apps/tenant/add")); }
} return request(super.createRequestPageTempletResponse("/apps/tenant/add"));
}
@RequestMapping("/save")
@Menu(type = "apps", subtype = "tenant") @RequestMapping("/save")
public ModelAndView save(HttpServletRequest request, @Valid Tenant tenant, @RequestParam(value = "tenantpic", required = false) MultipartFile tenantpic, @Valid String skills) throws NoSuchAlgorithmException, IOException { @Menu(type = "apps", subtype = "tenant")
Tenant tenanttemp = tenantRes.findByOrgidAndTenantname(super.getOrgid(request), tenant.getTenantname()); public ModelAndView save(HttpServletRequest request, @Valid Tenant tenant, @RequestParam(value = "tenantpic", required = false) MultipartFile tenantpic, @Valid String skills) throws IOException {
if (tenanttemp != null) { Tenant tenanttemp = tenantRes.findByOrgidAndTenantname(super.getOrgid(request), tenant.getTenantname());
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=tenantexist")); if (tenanttemp != null) {
} return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=tenantexist"));
tenantRes.save(tenant); }
if (tenantpic != null && tenantpic.getOriginalFilename().lastIndexOf(".") > 0) { tenantRes.save(tenant);
File logoDir = new File(path, "tenantpic"); if (tenantpic != null && tenantpic.getOriginalFilename() != null && tenantpic.getOriginalFilename().lastIndexOf(".") > 0) {
if (!logoDir.exists()) { File logoDir = new File(path, "tenantpic");
logoDir.mkdirs(); if (!logoDir.exists()) {
} //noinspection ResultOfMethodCallIgnored
String fileName = "tenantpic/" + tenant.getId() + tenantpic.getOriginalFilename().substring( logoDir.mkdirs();
tenantpic.getOriginalFilename().lastIndexOf(".")); }
FileCopyUtils.copy(tenantpic.getBytes(), new File(path, fileName)); String fileName = "tenantpic/" + tenant.getId() + tenantpic.getOriginalFilename().substring(
tenant.setTenantlogo(fileName); tenantpic.getOriginalFilename().lastIndexOf("."));
} FileCopyUtils.copy(tenantpic.getBytes(), new File(path, fileName));
String tenantid = tenant.getId(); tenant.setTenantlogo(fileName);
List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(tenantid); }
orgiSkillRelRes.delete(orgiSkillRelList); String tenantid = tenant.getId();
if (!StringUtils.isBlank(skills)) { List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(tenantid);
String[] skillsarray = skills.split(","); orgiSkillRelRes.deleteAll(orgiSkillRelList);
for (String skill : skillsarray) { if (!StringUtils.isBlank(skills)) {
OrgiSkillRel rel = new OrgiSkillRel(); String[] skillsarray = skills.split(",");
rel.setOrgi(tenant.getId()); for (String skill : skillsarray) {
rel.setSkillid(skill); OrgiSkillRel rel = new OrgiSkillRel();
rel.setCreater(super.getUser(request).getId()); rel.setOrgi(tenant.getId());
rel.setCreatetime(new Date()); rel.setSkillid(skill);
orgiSkillRelRes.save(rel); rel.setCreater(super.getUser(request).getId());
} rel.setCreatetime(new Date());
} orgiSkillRelRes.save(rel);
if (!StringUtils.isBlank(super.getUser(request).getOrgid())) { }
tenant.setOrgid(super.getUser(request).getOrgid()); }
} else { if (!StringUtils.isBlank(super.getUser(request).getOrgid())) {
tenant.setOrgid(MainContext.SYSTEM_ORGI); tenant.setOrgid(super.getUser(request).getOrgid());
} } else {
tenantRes.save(tenant); tenant.setOrgid(MainContext.SYSTEM_ORGI);
OnlineUserProxy.clean(tenantid); }
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index")); tenantRes.save(tenant);
} OnlineUserProxy.clean(tenantid);
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index"));
@RequestMapping("/edit") }
@Menu(type = "apps", subtype = "tenant")
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { @RequestMapping("/edit")
if (super.isTenantshare()) { @Menu(type = "apps", subtype = "tenant")
map.addAttribute("isShowSkillGroups", true); public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) {
List<Organ> organList = organRes.findByOrgiAndOrgid( if (super.isTenantshare()) {
super.getOrgiByTenantshare(request), super.getOrgid(request)); map.addAttribute("isShowSkillGroups", true);
map.addAttribute("skillGroups", organList); List<Organ> organList = organRes.findByOrgiAndOrgid(
List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(id); super.getOrgiByTenantshare(request), super.getOrgid(request));
map.addAttribute("orgiSkillRelList", orgiSkillRelList); map.addAttribute("skillGroups", organList);
} List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(id);
map.addAttribute("tenant", tenantRes.findById(id)); map.addAttribute("orgiSkillRelList", orgiSkillRelList);
return request(super.createRequestPageTempletResponse("/apps/tenant/edit")); }
} map.addAttribute("tenant", tenantRes.findById(id));
return request(super.createRequestPageTempletResponse("/apps/tenant/edit"));
@RequestMapping("/update") }
@Menu(type = "apps", subtype = "tenant", admin = true)
public ModelAndView update(HttpServletRequest request, @Valid Tenant tenant, @RequestParam(value = "tenantpic", required = false) MultipartFile tenantpic, @Valid String skills) throws NoSuchAlgorithmException, IOException { @RequestMapping("/update")
Tenant temp = tenantRes.findById(tenant.getId()); @Menu(type = "apps", subtype = "tenant", admin = true)
Tenant tenanttemp = tenantRes.findByOrgidAndTenantname(super.getOrgid(request), tenant.getTenantname()); public ModelAndView update(HttpServletRequest request, @NonNull @Valid Tenant tenant, @RequestParam(value = "tenantpic", required = false) MultipartFile tenantpic, @Valid String skills) throws IOException {
if (temp != null && tenanttemp != null && !temp.getId().equals(tenanttemp.getId())) { Tenant temp = tenantRes.findById(tenant.getId());
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=tenantexist")); Tenant tenanttemp = tenantRes.findByOrgidAndTenantname(super.getOrgid(request), tenant.getTenantname());
} if (temp != null && tenanttemp != null && !temp.getId().equals(tenanttemp.getId())) {
if (tenant != null) { return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=tenantexist"));
tenant.setCreatetime(temp.getCreatetime()); }
if (tenantpic != null && tenantpic.getOriginalFilename().lastIndexOf(".") > 0) { tenant.setCreatetime(temp.getCreatetime());
File logoDir = new File(path, "tenantpic"); if (tenantpic != null && tenantpic.getOriginalFilename() != null && tenantpic.getOriginalFilename().lastIndexOf(".") > 0) {
if (!logoDir.exists()) { File logoDir = new File(path, "tenantpic");
logoDir.mkdirs(); if (!logoDir.exists()) {
} //noinspection ResultOfMethodCallIgnored
String fileName = "tenantpic/" + tenant.getId() + tenantpic.getOriginalFilename().substring( logoDir.mkdirs();
tenantpic.getOriginalFilename().lastIndexOf(".")); }
FileCopyUtils.copy(tenantpic.getBytes(), new File(path, fileName)); String fileName = "tenantpic/" + tenant.getId() + tenantpic.getOriginalFilename().substring(
tenant.setTenantlogo(fileName); tenantpic.getOriginalFilename().lastIndexOf("."));
} else { FileCopyUtils.copy(tenantpic.getBytes(), new File(path, fileName));
tenant.setTenantlogo(temp.getTenantlogo()); tenant.setTenantlogo(fileName);
} } else {
if (!StringUtils.isBlank(super.getUser(request).getOrgid())) { tenant.setTenantlogo(temp.getTenantlogo());
tenant.setOrgid(super.getUser(request).getOrgid()); }
} else { if (!StringUtils.isBlank(super.getUser(request).getOrgid())) {
tenant.setOrgid(MainContext.SYSTEM_ORGI); tenant.setOrgid(super.getUser(request).getOrgid());
} } else {
tenantRes.save(tenant); tenant.setOrgid(MainContext.SYSTEM_ORGI);
List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(tenant.getId()); }
orgiSkillRelRes.delete(orgiSkillRelList); tenantRes.save(tenant);
if (!StringUtils.isBlank(skills)) { List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findByOrgi(tenant.getId());
String[] skillsarray = skills.split(","); orgiSkillRelRes.deleteAll(orgiSkillRelList);
for (String skill : skillsarray) { if (!StringUtils.isBlank(skills)) {
OrgiSkillRel rel = new OrgiSkillRel(); String[] skillsarray = skills.split(",");
rel.setOrgi(tenant.getId()); for (String skill : skillsarray) {
rel.setSkillid(skill); OrgiSkillRel rel = new OrgiSkillRel();
rel.setCreater(super.getUser(request).getId()); rel.setOrgi(tenant.getId());
rel.setCreatetime(new Date()); rel.setSkillid(skill);
orgiSkillRelRes.save(rel); rel.setCreater(super.getUser(request).getId());
} rel.setCreatetime(new Date());
} orgiSkillRelRes.save(rel);
OnlineUserProxy.clean(tenant.getId()); }
} }
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index")); OnlineUserProxy.clean(tenant.getId());
} return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index"));
}
@RequestMapping("/delete")
@Menu(type = "apps", subtype = "tenant") @RequestMapping("/delete")
public ModelAndView delete(HttpServletRequest request, @Valid Tenant tenant) { @Menu(type = "apps", subtype = "tenant")
Tenant temp = tenantRes.findById(tenant.getId()); public ModelAndView delete(@Valid Tenant tenant) {
if (tenant != null) { Tenant temp = tenantRes.findById(tenant.getId());
tenantRes.delete(temp); if (tenant != null) {
} tenantRes.delete(temp);
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index")); }
} return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index"));
}
@RequestMapping("/canswitch")
@Menu(type = "apps", subtype = "tenant") @RequestMapping("/canswitch")
public ModelAndView canswitch(HttpServletRequest request, @Valid Tenant tenant) throws UnsupportedEncodingException { @Menu(type = "apps", subtype = "tenant")
ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/")); public ModelAndView canswitch(HttpServletRequest request, @Valid Tenant tenant) throws UnsupportedEncodingException {
AgentStatus agentStatus = cache.findOneAgentStatusByAgentnoAndOrig( ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/"));
(super.getUser(request)).getId(), super.getOrgi(request)); AgentStatus agentStatus = cache.findOneAgentStatusByAgentnoAndOrig(
if (agentStatus == null && cache.getInservAgentUsersSizeByAgentnoAndOrgi( (super.getUser(request)).getId(), super.getOrgi(request));
super.getUser(request).getId(), super.getOrgi(request)) == 0) { if (agentStatus == null && cache.getInservAgentUsersSizeByAgentnoAndOrgi(
Tenant temp = tenantRes.findById(tenant.getId()); super.getUser(request).getId(), super.getOrgi(request)) == 0) {
if (temp != null) { Tenant temp = tenantRes.findById(tenant.getId());
super.getUser(request).setOrgi(temp.getId()); if (temp != null) {
} super.getUser(request).setOrgi(temp.getId());
return view; }
} return view;
if (agentStatus != null) { }
if (tenant.getId().equals(agentStatus.getOrgi())) { if (agentStatus != null) {
Tenant temp = tenantRes.findById(tenant.getId()); if (tenant.getId().equals(agentStatus.getOrgi())) {
if (temp != null) { Tenant temp = tenantRes.findById(tenant.getId());
super.getUser(request).setOrgi(temp.getId()); if (temp != null) {
} super.getUser(request).setOrgi(temp.getId());
return view; }
} else { return view;
Tenant temp = tenantRes.findById(agentStatus.getOrgi()); } else {
return request(super.createRequestPageTempletResponse( Tenant temp = tenantRes.findById(agentStatus.getOrgi());
"redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentStatus.getOrgi() + "&currentname=" + URLEncoder.encode( return request(super.createRequestPageTempletResponse(
temp != null ? temp.getTenantname() : "", "UTF-8"))); "redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentStatus.getOrgi() + "&currentname=" + URLEncoder.encode(
} temp != null ? temp.getTenantname() : "", "UTF-8")));
} }
AgentUser agentUser = agentUserRepository.findOneByAgentnoAndStatusAndOrgi( }
super.getUser(request).getId(), MainContext.AgentUserStatusEnum.INSERVICE.toString(), AgentUser agentUser = agentUserRepository.findOneByAgentnoAndStatusAndOrgi(
super.getOrgi(request)); super.getUser(request).getId(), MainContext.AgentUserStatusEnum.INSERVICE.toString(),
if (agentUser != null) { super.getOrgi(request));
if (tenant.getId().equals(agentUser.getOrgi())) { if (agentUser != null) {
Tenant temp = tenantRes.findById(tenant.getId()); if (tenant.getId().equals(agentUser.getOrgi())) {
if (temp != null) { Tenant temp = tenantRes.findById(tenant.getId());
super.getUser(request).setOrgi(temp.getId()); if (temp != null) {
} super.getUser(request).setOrgi(temp.getId());
return view; }
} else { return view;
Tenant temp = tenantRes.findById(agentUser.getOrgi()); } else {
return request(super.createRequestPageTempletResponse( Tenant temp = tenantRes.findById(agentUser.getOrgi());
"redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentUser.getOrgi() + "&currentname=" + URLEncoder.encode( return request(super.createRequestPageTempletResponse(
temp != null ? temp.getTenantname() : "", "UTF-8"))); "redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentUser.getOrgi() + "&currentname=" + URLEncoder.encode(
} temp != null ? temp.getTenantname() : "", "UTF-8")));
}
}
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=t0")); }
} return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=t0"));
} }
}

View File

@ -32,127 +32,124 @@ import com.chatopera.cc.socketio.message.Message;
import com.chatopera.cc.util.IP; import com.chatopera.cc.util.IP;
import com.chatopera.cc.util.IPTools; import com.chatopera.cc.util.IPTools;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.nio.charset.CharacterCodingException;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
@Controller @Controller
@RequestMapping("/service") @RequestMapping("/service")
@RequiredArgsConstructor
public class ChatServiceController extends Handler { public class ChatServiceController extends Handler {
private final static Logger logger = LoggerFactory.getLogger(ChatServiceController.class); private final static Logger logger = LoggerFactory.getLogger(ChatServiceController.class);
@Autowired @NonNull
private AgentUserProxy agentUserProxy; private final AgentUserProxy agentUserProxy;
@Autowired @NonNull
private AgentStatusProxy agentStatusProxy; private final AgentStatusProxy agentStatusProxy;
@Autowired @NonNull
private ACDAgentService acdAgentService; private final ACDAgentService acdAgentService;
@Autowired @NonNull
private ACDVisitorDispatcher acdVisitorDispatcher; private final ACDVisitorDispatcher acdVisitorDispatcher;
@Autowired @NonNull
private AgentServiceRepository agentServiceRes; private final AgentServiceRepository agentServiceRes;
@Autowired @NonNull
private AgentUserRepository agentUserRes; private final AgentUserRepository agentUserRes;
@Autowired @NonNull
private AgentStatusRepository agentStatusRepository; private final AgentStatusRepository agentStatusRepository;
@Autowired @NonNull
private AgentUserRepository agentUserRepository; private final AgentUserRepository agentUserRepository;
@Autowired @NonNull
private LeaveMsgRepository leaveMsgRes; private final LeaveMsgRepository leaveMsgRes;
@Autowired @NonNull
private LeaveMsgProxy leaveMsgProxy; private final LeaveMsgProxy leaveMsgProxy;
@Autowired @NonNull
private OrganRepository organRes; private final OrganRepository organRes;
@Autowired @NonNull
private OrganRepository organ; private final OrganRepository organ;
@Autowired @NonNull
private UserRepository user; private final UserRepository user;
@Autowired @NonNull
private UserRepository userRes; private final UserRepository userRes;
@Autowired @NonNull
private OrgiSkillRelRepository orgiSkillRelService; private final OrgiSkillRelRepository orgiSkillRelService;
@Autowired @NonNull
private UserProxy userProxy; private final UserProxy userProxy;
@Autowired @NonNull
private Cache cache; private final Cache cache;
@Autowired @NonNull
private PeerSyncIM peerSyncIM; private final PeerSyncIM peerSyncIM;
@Autowired @NonNull
private ACDMessageHelper acdMessageHelper; private final ACDMessageHelper acdMessageHelper;
@RequestMapping("/history/index") @RequestMapping("/history/index")
@Menu(type = "service", subtype = "history", admin = true) @Menu(type = "service", subtype = "history", admin = true)
public ModelAndView index(ModelMap map, HttpServletRequest request, final String username, final String channel, final String servicetype, final String allocation, final String servicetimetype, final String begin, final String end) { public ModelAndView index(ModelMap map, HttpServletRequest request, final String username, final String channel, final String servicetype, final String allocation, final String servicetimetype, final String begin, final String end) {
Page<AgentService> page = agentServiceRes.findAll(new Specification<AgentService>() { Page<AgentService> page = agentServiceRes.findAll((Specification<AgentService>) (root, query, cb) -> {
@Override List<Predicate> list = new ArrayList<>();
public Predicate toPredicate(Root<AgentService> root, CriteriaQuery<?> query, CriteriaBuilder cb) { if (StringUtils.isNotBlank(username)) {
List<Predicate> list = new ArrayList<Predicate>(); list.add(cb.equal(root.get("username").as(String.class), username));
if (StringUtils.isNotBlank(username)) {
list.add(cb.equal(root.get("username").as(String.class), username));
}
if (StringUtils.isNotBlank(channel)) {
list.add(cb.equal(root.get("channel").as(String.class), channel));
}
if (StringUtils.isNotBlank(servicetype) && StringUtils.isNotBlank(allocation)) {
list.add(cb.equal(root.get(servicetype).as(String.class), allocation));
}
if (StringUtils.isNotBlank(servicetimetype)) {
try {
if (StringUtils.isNotBlank(begin) && begin.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}")) {
list.add(cb.greaterThanOrEqualTo(
root.get(servicetimetype).as(Date.class),
MainUtils.simpleDateFormat.parse(begin)));
}
if (StringUtils.isNotBlank(end) && end.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}")) {
list.add(cb.lessThanOrEqualTo(
root.get(servicetimetype).as(Date.class),
MainUtils.dateFormate.parse(end + " 23:59:59")));
}
} catch (ParseException e) {
e.printStackTrace();
}
}
Predicate[] p = new Predicate[list.size()];
return cb.and(list.toArray(p));
} }
if (StringUtils.isNotBlank(channel)) {
list.add(cb.equal(root.get("channel").as(String.class), channel));
}
if (StringUtils.isNotBlank(servicetype) && StringUtils.isNotBlank(allocation)) {
list.add(cb.equal(root.get(servicetype).as(String.class), allocation));
}
if (StringUtils.isNotBlank(servicetimetype)) {
try {
if (StringUtils.isNotBlank(begin) && begin.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}")) {
list.add(cb.greaterThanOrEqualTo(
root.get(servicetimetype).as(Date.class),
MainUtils.simpleDateFormat.parse(begin)));
}
if (StringUtils.isNotBlank(end) && end.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}")) {
list.add(cb.lessThanOrEqualTo(
root.get(servicetimetype).as(Date.class),
MainUtils.dateFormate.parse(end + " 23:59:59")));
}
} catch (ParseException e) {
e.printStackTrace();
}
}
Predicate[] p = new Predicate[list.size()];
return cb.and(list.toArray(p));
}, PageRequest.of(super.getP(request), super.getPs(request), Direction.DESC, "createtime")); }, PageRequest.of(super.getP(request), super.getPs(request), Direction.DESC, "createtime"));
map.put("agentServiceList", page); map.put("agentServiceList", page);
map.put("username", username); map.put("username", username);
@ -199,7 +196,7 @@ public class ChatServiceController extends Handler {
} }
} }
List<AgentStatus> agentStatusList = cache.getAgentStatusBySkillAndOrgi(null, super.getOrgi(request)); List<AgentStatus> agentStatusList = cache.getAgentStatusBySkillAndOrgi(null, super.getOrgi(request));
List<String> usersids = new ArrayList<String>(); List<String> usersids = new ArrayList<>();
if (!agentStatusList.isEmpty()) { if (!agentStatusList.isEmpty()) {
for (AgentStatus agentStatus : agentStatusList) { for (AgentStatus agentStatus : agentStatusList) {
if (agentStatus != null) { if (agentStatus != null) {
@ -207,16 +204,18 @@ public class ChatServiceController extends Handler {
} }
} }
} }
List<User> userList = userRes.findAll(usersids); List<User> userList = userRes.findAllById(usersids);
for (User user : userList) { for (User user : userList) {
user.setAgentStatus(cache.findOneAgentStatusByAgentnoAndOrig(user.getId(), super.getOrgi(request))); user.setAgentStatus(cache.findOneAgentStatusByAgentnoAndOrig(user.getId(), super.getOrgi(request)));
userProxy.attachOrgansPropertiesForUser(user); userProxy.attachOrgansPropertiesForUser(user);
} }
map.addAttribute("userList", userList); map.addAttribute("userList", userList);
map.addAttribute("userid", agentService.getUserid()); if (agentService != null) {
map.addAttribute("agentserviceid", agentService.getId()); map.addAttribute("userid", agentService.getUserid());
map.addAttribute("agentuserid", agentService.getAgentuserid()); map.addAttribute("agentserviceid", agentService.getId());
map.addAttribute("agentservice", agentService); map.addAttribute("agentuserid", agentService.getAgentuserid());
map.addAttribute("agentservice", agentService);
}
map.addAttribute("skillGroups", skillGroups); map.addAttribute("skillGroups", skillGroups);
map.addAttribute("currentorgan", currentOrgan); map.addAttribute("currentorgan", currentOrgan);
} }
@ -226,10 +225,11 @@ public class ChatServiceController extends Handler {
@RequestMapping(value = "/transfer/save") @RequestMapping(value = "/transfer/save")
@Menu(type = "apps", subtype = "transfersave") @Menu(type = "apps", subtype = "transfersave")
public ModelAndView transfersave(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String agentno, @Valid String memo) throws CharacterCodingException { public ModelAndView transfersave(HttpServletRequest request, @Valid String id, @Valid String agentno, @Valid String memo) {
if (StringUtils.isNotBlank(id)) { if (StringUtils.isNotBlank(id)) {
AgentService agentService = agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request)); AgentService agentService = Objects.requireNonNull(agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request)));
final User targetAgent = userRes.findOne(agentno); final User targetAgent = userRes.findById(agentno)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Agent %s not found", agentno)));
AgentUser agentUser = null; AgentUser agentUser = null;
Optional<AgentUser> agentUserOpt = cache.findOneAgentUserByUserIdAndOrgi( Optional<AgentUser> agentUserOpt = cache.findOneAgentUserByUserIdAndOrgi(
agentService.getUserid(), super.getOrgi(request)); agentService.getUserid(), super.getOrgi(request));
@ -303,15 +303,13 @@ public class ChatServiceController extends Handler {
} }
} }
if (agentService != null) { agentService.setAgentno(agentno);
agentService.setAgentno(agentno); if (StringUtils.isNotBlank(memo)) {
if (StringUtils.isNotBlank(memo)) { agentService.setTransmemo(memo);
agentService.setTransmemo(memo);
}
agentService.setTrans(true);
agentService.setTranstime(new Date());
agentServiceRes.save(agentService);
} }
agentService.setTrans(true);
agentService.setTranstime(new Date());
agentServiceRes.save(agentService);
} }
return request(super.createRequestPageTempletResponse("redirect:/service/current/index.html")); return request(super.createRequestPageTempletResponse("redirect:/service/current/index.html"));
@ -319,7 +317,7 @@ public class ChatServiceController extends Handler {
@RequestMapping("/current/end") @RequestMapping("/current/end")
@Menu(type = "service", subtype = "current", admin = true) @Menu(type = "service", subtype = "current", admin = true)
public ModelAndView end(ModelMap map, HttpServletRequest request, @Valid String id) throws Exception { public ModelAndView end(HttpServletRequest request, @Valid String id) throws Exception {
if (StringUtils.isNotBlank(id)) { if (StringUtils.isNotBlank(id)) {
AgentService agentService = agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request)); AgentService agentService = agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request));
if (agentService != null) { if (agentService != null) {
@ -338,19 +336,12 @@ public class ChatServiceController extends Handler {
/** /**
* 邀请 * 邀请
*
* @param map
* @param request
* @param id
* @return
* @throws Exception
*/ */
@RequestMapping("/current/invite") @RequestMapping("/current/invite")
@Menu(type = "service", subtype = "current", admin = true) @Menu(type = "service", subtype = "current", admin = true)
public ModelAndView currentinvite( public ModelAndView currentinvite(
ModelMap map,
final HttpServletRequest request, final HttpServletRequest request,
final @Valid String id) throws Exception { final @Valid String id) {
if (StringUtils.isNotBlank(id)) { if (StringUtils.isNotBlank(id)) {
AgentService agentService = agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request)); AgentService agentService = agentServiceRes.findByIdAndOrgi(id, super.getOrgi(request));
if (agentService != null) { if (agentService != null) {
@ -402,7 +393,7 @@ public class ChatServiceController extends Handler {
Page<AgentUser> agentUserList = agentUserRes.findByOrgiAndStatus( Page<AgentUser> agentUserList = agentUserRes.findByOrgiAndStatus(
super.getOrgi(request), MainContext.AgentUserStatusEnum.INQUENE.toString(), super.getOrgi(request), MainContext.AgentUserStatusEnum.INQUENE.toString(),
PageRequest.of(super.getP(request), super.getPs(request), Direction.DESC, "createtime")); PageRequest.of(super.getP(request), super.getPs(request), Direction.DESC, "createtime"));
List<String> skillGroups = new ArrayList<String>(); List<String> skillGroups = new ArrayList<>();
for (AgentUser agentUser : agentUserList.getContent()) { for (AgentUser agentUser : agentUserList.getContent()) {
agentUser.setWaittingtime((int) (System.currentTimeMillis() - agentUser.getCreatetime().getTime())); agentUser.setWaittingtime((int) (System.currentTimeMillis() - agentUser.getCreatetime().getTime()));
if (StringUtils.isNotBlank(agentUser.getSkill())) { if (StringUtils.isNotBlank(agentUser.getSkill())) {
@ -410,7 +401,7 @@ public class ChatServiceController extends Handler {
} }
} }
if (skillGroups.size() > 0) { if (skillGroups.size() > 0) {
List<Organ> organList = organRes.findAll(skillGroups); List<Organ> organList = organRes.findAllById(skillGroups);
for (AgentUser agentUser : agentUserList.getContent()) { for (AgentUser agentUser : agentUserList.getContent()) {
if (StringUtils.isNotBlank(agentUser.getSkill())) { if (StringUtils.isNotBlank(agentUser.getSkill())) {
for (Organ organ : organList) { for (Organ organ : organList) {
@ -428,7 +419,7 @@ public class ChatServiceController extends Handler {
@RequestMapping("/quene/clean") @RequestMapping("/quene/clean")
@Menu(type = "service", subtype = "queneclean", admin = true) @Menu(type = "service", subtype = "queneclean", admin = true)
public ModelAndView clean(ModelMap map, HttpServletRequest request, @Valid String id) { public ModelAndView clean(HttpServletRequest request, @Valid String id) {
AgentUser agentUser = agentUserRes.findByIdAndOrgi(id, super.getOrgi(request)); AgentUser agentUser = agentUserRes.findByIdAndOrgi(id, super.getOrgi(request));
if (agentUser != null && agentUser.getStatus().equals(MainContext.AgentUserStatusEnum.INQUENE.toString())) { if (agentUser != null && agentUser.getStatus().equals(MainContext.AgentUserStatusEnum.INQUENE.toString())) {
agentUser.setAgentno(null); agentUser.setAgentno(null);
@ -443,7 +434,7 @@ public class ChatServiceController extends Handler {
@RequestMapping("/quene/invite") @RequestMapping("/quene/invite")
@Menu(type = "service", subtype = "invite", admin = true) @Menu(type = "service", subtype = "invite", admin = true)
public ModelAndView invite(ModelMap map, HttpServletRequest request, @Valid String id) throws Exception { public ModelAndView invite(HttpServletRequest request, @Valid String id) {
final User logined = super.getUser(request); final User logined = super.getUser(request);
final String orgi = logined.getOrgi(); final String orgi = logined.getOrgi();
AgentUser agentUser = agentUserRes.findByIdAndOrgi(id, super.getOrgi(request)); AgentUser agentUser = agentUserRes.findByIdAndOrgi(id, super.getOrgi(request));
@ -455,10 +446,6 @@ public class ChatServiceController extends Handler {
/** /**
* 管理员查看在线坐席 * 管理员查看在线坐席
*
* @param map
* @param request
* @return
*/ */
@RequestMapping("/agent/index") @RequestMapping("/agent/index")
@Menu(type = "service", subtype = "onlineagent", admin = true) @Menu(type = "service", subtype = "onlineagent", admin = true)
@ -476,21 +463,16 @@ public class ChatServiceController extends Handler {
/** /**
* 查看离线坐席 * 查看离线坐席
*
* @param map
* @param request
* @param id
* @return
*/ */
@RequestMapping("/agent/offline") @RequestMapping("/agent/offline")
@Menu(type = "service", subtype = "offline", admin = true) @Menu(type = "service", subtype = "offline", admin = true)
public ModelAndView offline(ModelMap map, HttpServletRequest request, @Valid String id) { public ModelAndView offline(HttpServletRequest request, @Valid String id) {
AgentStatus agentStatus = agentStatusRepository.findByIdAndOrgi(id, super.getOrgi(request)); AgentStatus agentStatus = agentStatusRepository.findByIdAndOrgi(id, super.getOrgi(request));
if (agentStatus != null) { if (agentStatus != null) {
agentStatusRepository.delete(agentStatus); agentStatusRepository.delete(agentStatus);
cache.deleteAgentStatusByAgentnoAndOrgi(agentStatus.getAgentno(), super.getOrgi(request));
} }
cache.deleteAgentStatusByAgentnoAndOrgi(agentStatus.getAgentno(), super.getOrgi(request));
agentStatusProxy.broadcastAgentsStatus( agentStatusProxy.broadcastAgentsStatus(
super.getOrgi(request), "agent", "offline", super.getUser(request).getId()); super.getOrgi(request), "agent", "offline", super.getUser(request).getId());
@ -500,10 +482,6 @@ public class ChatServiceController extends Handler {
/** /**
* 非管理员坐席 * 非管理员坐席
*
* @param map
* @param request
* @return
*/ */
@RequestMapping("/user/index") @RequestMapping("/user/index")
@Menu(type = "service", subtype = "userlist", admin = true) @Menu(type = "service", subtype = "userlist", admin = true)
@ -552,9 +530,9 @@ public class ChatServiceController extends Handler {
@RequestMapping("/leavemsg/delete") @RequestMapping("/leavemsg/delete")
@Menu(type = "service", subtype = "leavemsg", admin = true) @Menu(type = "service", subtype = "leavemsg", admin = true)
public ModelAndView leavemsg(ModelMap map, HttpServletRequest request, @Valid String id) { public ModelAndView leavemsg(@Valid String id) {
if (StringUtils.isNotBlank(id)) { if (StringUtils.isNotBlank(id)) {
leaveMsgRes.delete(id); leaveMsgRes.deleteById(id);
} }
return request(super.createRequestPageTempletResponse("redirect:/service/leavemsg/index.html")); return request(super.createRequestPageTempletResponse("redirect:/service/leavemsg/index.html"));
} }

View File

@ -1,56 +1,56 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.persistence.repository; package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.AgentService; import com.chatopera.cc.model.AgentService;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.Nullable;
import java.util.List;
import java.util.Optional; import java.util.List;
import java.util.Optional;
public interface AgentServiceRepository
extends JpaRepository<AgentService, String> public interface AgentServiceRepository extends JpaRepository<AgentService, String> {
{ @Nullable
AgentService findByIdAndOrgi(String paramString, String orgi); AgentService findByIdAndOrgi(String paramString, String orgi);
List<AgentService> findByUseridAndOrgiOrderByLogindateDesc(String paramString, String orgi); List<AgentService> findByUseridAndOrgiOrderByLogindateDesc(String paramString, String orgi);
@Query(value = "SELECT * FROM uk_agentservice WHERE userid= ?1 AND orgi = ?2 ORDER BY logindate DESC LIMIT 1", nativeQuery = true) @Query(value = "SELECT * FROM uk_agentservice WHERE userid= ?1 AND orgi = ?2 ORDER BY logindate DESC LIMIT 1", nativeQuery = true)
Optional<AgentService> findOneByUseridAndOrgiOrderByLogindateDesc(String userid, String orgi); Optional<AgentService> findOneByUseridAndOrgiOrderByLogindateDesc(String userid, String orgi);
AgentService findFirstByUserid(String userid); AgentService findFirstByUserid(String userid);
Page<AgentService> findByOrgi(String orgi, Pageable paramPageable); Page<AgentService> findByOrgi(String orgi, Pageable paramPageable);
Page<AgentService> findByOrgiAndSatisfaction(String orgi, boolean satisfaction, Pageable paramPageable); Page<AgentService> findByOrgiAndSatisfaction(String orgi, boolean satisfaction, Pageable paramPageable);
Page<AgentService> findByOrgiAndStatus(String orgi, String status, Pageable paramPageable); Page<AgentService> findByOrgiAndStatus(String orgi, String status, Pageable paramPageable);
List<AgentService> findByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi); List<AgentService> findByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi);
int countByUseridAndOrgiAndStatus(String userid, String orgi, String status); int countByUseridAndOrgiAndStatus(String userid, String orgi, String status);
List<AgentService> findByUseridAndOrgiAndStatus(String userid, String orgi, String status, Sort sort); List<AgentService> findByUseridAndOrgiAndStatus(String userid, String orgi, String status, Sort sort);
Page<AgentService> findAll(Specification<AgentService> spec, Pageable pageable); //分页按条件查询 Page<AgentService> findAll(Specification<AgentService> spec, Pageable pageable); //分页按条件查询
} }

View File

@ -1,88 +1,88 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.persistence.repository; package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.AgentUser; import com.chatopera.cc.model.AgentUser;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface AgentUserRepository extends JpaRepository<AgentUser, String> { public interface AgentUserRepository extends JpaRepository<AgentUser, String> {
AgentUser findByIdAndOrgi(String paramString, String orgi); AgentUser findByIdAndOrgi(String paramString, String orgi);
@Query(value = "SELECT * FROM uk_agentuser WHERE userid = ?1 AND orgi = ?2 ORDER BY createtime DESC LIMIT 1", nativeQuery = true) @Query(value = "SELECT * FROM uk_agentuser WHERE userid = ?1 AND orgi = ?2 ORDER BY createtime DESC LIMIT 1", nativeQuery = true)
Optional<AgentUser> findOneByUseridAndOrgi(String userid, String orgi); Optional<AgentUser> findOneByUseridAndOrgi(String userid, String orgi);
@Query(value = "SELECT * FROM uk_agentuser WHERE userid = ?1 LIMIT 1", nativeQuery = true) // @Query(value = "SELECT * FROM uk_agentuser WHERE userid = ?1 LIMIT 1", nativeQuery = true)
AgentUser findOneByUserid(final String userid); // AgentUser findOneByUserid(final String userid);
List<AgentUser> findByUseridAndOrgi(String userid, String orgi); List<AgentUser> findByUseridAndOrgi(String userid, String orgi);
List<AgentUser> findByUseridAndStatus(String userid, String status); // List<AgentUser> findByUseridAndStatus(String userid, String status);
List<AgentUser> findByAgentnoAndOrgi(String agentno, String orgi, Sort sort); List<AgentUser> findByAgentnoAndOrgi(String agentno, String orgi, Sort sort);
List<AgentUser> findByAgentnoAndOrgi(String agentno, String orgi); // List<AgentUser> findByAgentnoAndOrgi(String agentno, String orgi);
Page<AgentUser> findByOrgiAndStatus(String orgi, String status, Pageable page); Page<AgentUser> findByOrgiAndStatus(String orgi, String status, Pageable page);
List<AgentUser> findByOrgiAndStatus(final String orgi, final String status, final Sort sort); // List<AgentUser> findByOrgiAndStatus(final String orgi, final String status, final Sort sort);
List<AgentUser> findByOrgiAndStatusAndAgentnoIsNot(final String orgi, final String status, final String agentno, final Sort sort); List<AgentUser> findByOrgiAndStatusAndAgentnoIsNot(final String orgi, final String status, final String agentno, final Sort sort);
List<AgentUser> findByOrgiAndStatusAndSkillAndAgentno(final String orgi, final String status, final String skill, final String agentno, Sort defaultSort); List<AgentUser> findByOrgiAndStatusAndSkillAndAgentno(final String orgi, final String status, final String skill, final String agentno, Sort defaultSort);
List<AgentUser> findByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi); List<AgentUser> findByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi);
List<AgentUser> findByOrgiAndStatusAndSkillAndAgentnoIsNot(final String orgi, final String status, final String skill, final String agentno, final Sort sort); List<AgentUser> findByOrgiAndStatusAndSkillAndAgentnoIsNot(final String orgi, final String status, final String skill, final String agentno, final Sort sort);
List<AgentUser> findByOrgiAndStatusAndAgentno(final String orgi, final String status, final String agentno, final Sort defaultSort); List<AgentUser> findByOrgiAndStatusAndAgentno(final String orgi, final String status, final String agentno, final Sort defaultSort);
@Query(value = "SELECT a FROM AgentUser a WHERE a.userid in(:userids)") @Query(value = "SELECT a FROM AgentUser a WHERE a.userid in(:userids)")
List<AgentUser> findAllByUserids(@Param("userids") List<String> userids); List<AgentUser> findAllByUserids(@Param("userids") List<String> userids);
int countByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi); // int countByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi);
AgentUser findOneByAgentnoAndStatusAndOrgi(String id, String status, String orgi); AgentUser findOneByAgentnoAndStatusAndOrgi(String id, String status, String orgi);
@Query(value = "SELECT * FROM uk_agentuser AS u " + @Query(value = "SELECT * FROM uk_agentuser AS u " +
"LEFT JOIN uk_agentuser_contacts AS c " + "LEFT JOIN uk_agentuser_contacts AS c " +
"ON u.userid = c.userid WHERE c.id = ?1 AND NOT u.status = ?2 AND c.orgi = ?3 LIMIT 1", nativeQuery = true) "ON u.userid = c.userid WHERE c.id = ?1 AND NOT u.status = ?2 AND c.orgi = ?3 LIMIT 1", nativeQuery = true)
AgentUser findOneByContactIdAndStatusNotAndOrgi(final String contactid, final String status, final String orgi); AgentUser findOneByContactIdAndStatusNotAndOrgi(final String contactid, final String status, final String orgi);
@Query(value = "SELECT * FROM uk_agentuser AS u " + @Query(value = "SELECT * FROM uk_agentuser AS u " +
"LEFT JOIN uk_agentuser_contacts AS c " + "LEFT JOIN uk_agentuser_contacts AS c " +
"ON u.userid = c.userid WHERE c.contactsid = ?1 " + "ON u.userid = c.userid WHERE c.contactsid = ?1 " +
"AND c.channel = ?3 AND NOT u.status = ?2 AND c.orgi = ?4 " + "AND c.channel = ?3 AND NOT u.status = ?2 AND c.orgi = ?4 " +
"ORDER BY u.createtime DESC LIMIT 1", nativeQuery = true) "ORDER BY u.createtime DESC LIMIT 1", nativeQuery = true)
Optional<AgentUser> findOneByContactIdAndStatusNotAndChannelAndOrgi(final String contactid, final String status, final String channel, final String orgi); Optional<AgentUser> findOneByContactIdAndStatusNotAndChannelAndOrgi(final String contactid, final String status, final String channel, final String orgi);
@Query(value = "SELECT * FROM uk_agentuser AS u " + @Query(value = "SELECT * FROM uk_agentuser AS u " +
"LEFT JOIN uk_agentuser_contacts AS c " + "LEFT JOIN uk_agentuser_contacts AS c " +
"ON u.userid = c.userid WHERE c.contactsid = ?1 " + "ON u.userid = c.userid WHERE c.contactsid = ?1 " +
"AND c.channel = ?2 AND c.orgi = ?3 " + "AND c.channel = ?2 AND c.orgi = ?3 " +
"ORDER BY u.createtime DESC LIMIT 1", nativeQuery = true) "ORDER BY u.createtime DESC LIMIT 1", nativeQuery = true)
Optional<AgentUser> findOneByContactIdAndChannelAndOrgi(final String contactid, final String channel, final String orgi); Optional<AgentUser> findOneByContactIdAndChannelAndOrgi(final String contactid, final String channel, final String orgi);
} }

View File

@ -18,53 +18,40 @@ package com.chatopera.cc.proxy;
import com.chatopera.cc.cache.Cache; import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.model.AgentService; import com.chatopera.cc.model.AgentService;
import com.chatopera.cc.model.AgentUser;
import com.chatopera.cc.model.BlackEntity; import com.chatopera.cc.model.BlackEntity;
import com.chatopera.cc.model.User; import com.chatopera.cc.model.User;
import com.chatopera.cc.persistence.repository.AgentServiceRepository; import com.chatopera.cc.persistence.repository.AgentServiceRepository;
import com.chatopera.cc.persistence.repository.AgentUserRepository;
import com.chatopera.cc.persistence.repository.BlackListRepository; import com.chatopera.cc.persistence.repository.BlackListRepository;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
@Component @Component
@RequiredArgsConstructor
public class BlackEntityProxy { public class BlackEntityProxy {
@Autowired @NonNull
private BlackListRepository blackListRes; private final BlackListRepository blackListRes;
@Autowired @NonNull
private Cache cache; private final Cache cache;
@Autowired @NonNull
private AgentUserRepository agentUserRepository; private final AgentServiceRepository agentServiceRes;
@Autowired
private AgentServiceRepository agentServiceRes;
/** /**
* 更新或创建黑名单记录 * 更新或创建黑名单记录
*
* @param pre
* @param owner
* @param userid
* @param orgi
* @param agentserviceid
* @param agentuserid
* @return
*/ */
public BlackEntity updateOrCreateBlackEntity( public void updateOrCreateBlackEntity(
final BlackEntity pre, final BlackEntity pre,
final User owner, final User owner,
final String userid, final String userid,
final String orgi, final String orgi,
final String agentserviceid, final String agentserviceid) {
final String agentuserid) {
final BlackEntity blackEntityUpdated = cache.findOneBlackEntityByUserIdAndOrgi( final BlackEntity blackEntityUpdated = cache.findOneBlackEntityByUserIdAndOrgi(
userid, orgi).orElseGet( userid, orgi).orElseGet(
() -> { () -> {
@ -102,6 +89,5 @@ public class BlackEntityProxy {
blackListRes.save(blackEntityUpdated); blackListRes.save(blackEntityUpdated);
return blackEntityUpdated;
} }
} }

View File

@ -22,12 +22,12 @@ import com.chatopera.cc.persistence.es.ContactsRepository;
import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.AgentUserRepository;
import com.chatopera.cc.persistence.repository.OnlineUserRepository; import com.chatopera.cc.persistence.repository.OnlineUserRepository;
import com.chatopera.cc.persistence.repository.SNSAccountRepository; import com.chatopera.cc.persistence.repository.SNSAccountRepository;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
@ -37,34 +37,27 @@ import java.util.*;
* 向联系人发送消息 * 向联系人发送消息
*/ */
@Component @Component
@RequiredArgsConstructor
public class ContactsProxy { public class ContactsProxy {
private final static Logger logger = LoggerFactory.getLogger(ContactsProxy.class); private final static Logger logger = LoggerFactory.getLogger(ContactsProxy.class);
@Autowired @NonNull
private Cache cache; private final Cache cache;
@Autowired @NonNull
private AgentUserRepository agentUserRes; private final AgentUserRepository agentUserRes;
@Autowired @NonNull
private ContactsRepository contactsRes; private final ContactsRepository contactsRes;
@Autowired
private OnlineUserRepository onlineUserRes;
@Value("${web.upload-path}")
private String path;
@Autowired
private SNSAccountRepository snsAccountRes;
@NonNull
private final OnlineUserRepository onlineUserRes;
@NonNull
private final SNSAccountRepository snsAccountRes;
/** /**
* 在传输SkypeId中有操作混入了非法字符 * 在传输SkypeId中有操作混入了非法字符
*
* @param dirty
* @return
*/ */
public String sanitizeSkypeId(final String dirty) { public String sanitizeSkypeId(final String dirty) {
if (dirty != null) { if (dirty != null) {
@ -80,7 +73,6 @@ public class ContactsProxy {
* *
* @param logined 当前查询该信息的访客 * @param logined 当前查询该信息的访客
* @param contactid 目标联系人ID * @param contactid 目标联系人ID
* @return
*/ */
public List<MainContext.ChannelType> liveApproachChannelsByContactid( public List<MainContext.ChannelType> liveApproachChannelsByContactid(
final User logined, final User logined,
@ -106,9 +98,7 @@ public class ContactsProxy {
if (!cache.existBlackEntityByUserIdAndOrgi(p.getUserid(), logined.getOrgi())) { if (!cache.existBlackEntityByUserIdAndOrgi(p.getUserid(), logined.getOrgi())) {
// 访客在线 WebIM排队或服务中 // 访客在线 WebIM排队或服务中
result.add(MainContext.ChannelType.WEBIM); result.add(MainContext.ChannelType.WEBIM);
} else { } // else 该访客被拉黑
// 该访客被拉黑
}
}); });
// 查看 Skype 渠道 // 查看 Skype 渠道
@ -162,10 +152,6 @@ public class ContactsProxy {
/** /**
* 批量查询联系人的可触达状态 * 批量查询联系人的可触达状态
*
* @param contacts
* @param map
* @param user
*/ */
public void bindContactsApproachableData(final Page<Contacts> contacts, final ModelMap map, final User user) { public void bindContactsApproachableData(final Page<Contacts> contacts, final ModelMap map, final User user) {
Set<String> approachable = new HashSet<>(); Set<String> approachable = new HashSet<>();
@ -184,23 +170,14 @@ public class ContactsProxy {
/** /**
* 检查Skype渠道是否被建立 * 检查Skype渠道是否被建立
*
* @return
*/ */
public boolean isSkypeSetup(final String orgi) { public boolean isSkypeSetup(final String orgi) {
if (MainContext.hasModule(Constants.CSKEFU_MODULE_SKYPE) && snsAccountRes.countBySnstypeAndOrgi( return MainContext.hasModule(Constants.CSKEFU_MODULE_SKYPE) && snsAccountRes.countBySnstypeAndOrgi(
Constants.CSKEFU_MODULE_SKYPE, orgi) > 0) { Constants.CSKEFU_MODULE_SKYPE, orgi) > 0;
return true;
}
return false;
} }
/** /**
* 判断编辑是否变更 * 判断编辑是否变更
*
* @param newValue
* @param oldValue
* @return
*/ */
public boolean determineChange(Contacts newValue, Contacts oldValue) { public boolean determineChange(Contacts newValue, Contacts oldValue) {
return (!newValue.getName().equals(oldValue.getName()) || return (!newValue.getName().equals(oldValue.getName()) ||