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

Fix TenantRepository related class

This commit is contained in:
dengchao@xgtl 2020-04-16 17:11:10 +08:00
parent 540a480cd1
commit 7d882fdd82
8 changed files with 280 additions and 516 deletions

View File

@ -31,15 +31,18 @@ import com.chatopera.cc.model.User;
import com.chatopera.cc.persistence.blob.JpaBlobHelper;
import com.chatopera.cc.persistence.repository.StreamingFileRepository;
import com.chatopera.cc.persistence.repository.TenantRepository;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.Cookie;
@ -51,32 +54,26 @@ import java.util.Map;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
@Controller
@SessionAttributes
@NoArgsConstructor
public class Handler {
private static final Logger logger = LoggerFactory.getLogger(Handler.class);
@Autowired
private TenantRepository tenantRes;
@Autowired
private JpaBlobHelper jpaBlobHelper;
@Autowired
private StreamingFileRepository streamingFileRes;
@Autowired
private Cache cache;
@Autowired
private AuthToken authToken;
public final static int PAGE_SIZE_BG = 1;
public final static int PAGE_SIZE_TW = 20;
public final static int PAGE_SIZE_FV = 50;
public final static int PAGE_SIZE_HA = 100;
private long starttime = System.currentTimeMillis();
private static final Logger logger = LoggerFactory.getLogger(Handler.class);
@Autowired
private TenantRepository tenantRes;
@Autowired
private JpaBlobHelper jpaBlobHelper;
@Autowired
private StreamingFileRepository streamingFileRes;
@Autowired
private Cache cache;
@Autowired
private AuthToken authToken;
private long startTime = System.currentTimeMillis();
public User getUser(HttpServletRequest request) {
User user = (User) request.getSession(true).getAttribute(Constants.USER_SESSION_NAME);
@ -108,13 +105,8 @@ public class Handler {
/**
* 构建ElasticSearch基于部门查询的Filter
*
* @param request
* @param boolQueryBuilder
* @return
* @throws CSKefuException
*/
public boolean esOrganFilter(final HttpServletRequest request, final BoolQueryBuilder boolQueryBuilder) throws CSKefuException {
public boolean esOrganFilter(final HttpServletRequest request) throws CSKefuException {
// 组合部门条件
User u = getUser(request);
if (u == null) {
@ -122,7 +114,7 @@ public class Handler {
} else if (u.isAdmin()) {
// 管理员, 查看任何数据
return true;
} else {
// } else {
// 用户在部门中通过部门过滤数据
// String[] values = u.getAffiliates().toArray(new String[u.getAffiliates().size()]);
// boolQueryBuilder.filter(termsQuery("organ", values));
@ -133,8 +125,7 @@ public class Handler {
}
/**
* @param queryBuilder
* @param request
*
*/
public BoolQueryBuilder search(BoolQueryBuilder queryBuilder, ModelMap map, HttpServletRequest request) {
queryBuilder.must(termQuery("orgi", this.getOrgi(request)));
@ -287,11 +278,6 @@ public class Handler {
* 创建或从HTTP会话中查找到访客的User对象该对象不在数据库中属于临时会话
* 这个User很可能是打开一个WebIM访客聊天控件随机生成用户名之后和Contact关联
* 这个用户可能关联一个OnlineUser如果开始给TA分配坐席
*
* @param request
* @param userid
* @param nickname
* @return
*/
public User getIMUser(HttpServletRequest request, String userid, String nickname) {
User user = (User) request.getSession(true).getAttribute(Constants.IM_USER_SESSION_NAME);
@ -361,9 +347,6 @@ public class Handler {
/**
* 创建系统监控的 模板页面
*
* @param page
* @return
*/
public Viewport createAdminTempletResponse(String page) {
return new Viewport("/admin/include/tpl", page);
@ -371,9 +354,6 @@ public class Handler {
/**
* 创建系统监控的 模板页面
*
* @param page
* @return
*/
public Viewport createAppsTempletResponse(String page) {
return new Viewport("/apps/include/tpl", page);
@ -381,9 +361,6 @@ public class Handler {
/**
* 创建系统监控的 模板页面
*
* @param page
* @return
*/
public Viewport createEntIMTempletResponse(final String page) {
return new Viewport("/apps/entim/include/tpl", page);
@ -394,8 +371,7 @@ public class Handler {
}
/**
* @param data
* @return
*
*/
public ModelAndView request(Viewport data) {
return new ModelAndView(data.getTemplet() != null ? data.getTemplet() : data.getPage(), "data", data);
@ -442,24 +418,12 @@ public class Handler {
}
public int get50Ps(HttpServletRequest request) {
int pagesize = PAGE_SIZE_FV;
String ps = request.getParameter("ps");
if (StringUtils.isNotBlank(ps) && ps.matches("[\\d]*")) {
pagesize = Integer.parseInt(ps);
}
return pagesize;
}
public String getOrgi(HttpServletRequest request) {
return getUser(request).getOrgi();
}
/**
* 机构id
*
* @param request
* @return
*/
public String getOrgid(HttpServletRequest request) {
User u = getUser(request);
@ -467,14 +431,13 @@ public class Handler {
}
public Tenant getTenant(HttpServletRequest request) {
return tenantRes.findById(getOrgi(request));
String id = getOrgi(request);
return tenantRes.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Tenant %s not found", id)));
}
/**
* 根据是否租户共享获取orgi
*
* @param request
* @return
*/
public String getOrgiByTenantshare(HttpServletRequest request) {
SystemConfig systemConfig = MainUtils.getSystemConfig();
@ -487,8 +450,6 @@ public class Handler {
/**
* 判断是否租户共享
*
* @return
*/
public boolean isTenantshare() {
SystemConfig systemConfig = MainUtils.getSystemConfig();
@ -497,8 +458,6 @@ public class Handler {
/**
* 判断是否多租户
*
* @return
*/
public boolean isEnabletneant() {
SystemConfig systemConfig = MainUtils.getSystemConfig();
@ -507,28 +466,22 @@ public class Handler {
/**
* 判断是否多租户
*
* @return
*/
public boolean isTenantconsole() {
SystemConfig systemConfig = MainUtils.getSystemConfig();
return systemConfig != null && systemConfig.isEnabletneant() && systemConfig.isTenantconsole();
}
public long getStarttime() {
return starttime;
public long getStartTime() {
return startTime;
}
public void setStarttime(long starttime) {
this.starttime = starttime;
public void setStartTime(long startTime) {
this.startTime = startTime;
}
/**
* 使用Blob保存文件
*
* @param multipart
* @return id
* @throws IOException
*/
public String saveImageFileWithMultipart(MultipartFile multipart) throws IOException {
StreamingFile sf = new StreamingFile();

View File

@ -108,7 +108,7 @@ public class ContactsController extends Handler {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/contacts/index"));
}
@ -146,7 +146,7 @@ public class ContactsController extends Handler {
final User logined = super.getUser(request);
final String orgi = logined.getOrgi();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/contacts/index"));
}
@ -181,7 +181,7 @@ public class ContactsController extends Handler {
final User logined = super.getUser(request);
final String orgi = logined.getOrgi();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/contacts/index"));
}
@ -215,7 +215,7 @@ public class ContactsController extends Handler {
final User logined = super.getUser(request);
final String orgi = logined.getOrgi();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/contacts/index"));
}
@ -491,7 +491,7 @@ public class ContactsController extends Handler {
final User logined = super.getUser(request);
final String orgi = logined.getOrgi();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return;
}
boolQueryBuilder.must(termQuery("datastatus", false)); //只导出 数据删除状态 未删除的 数据
@ -555,7 +555,7 @@ public class ContactsController extends Handler {
final String orgi = logined.getOrgi();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
map.put("msg", msg);
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/contacts/embed/index"));
}
if (StringUtils.isNotBlank(q)) {

View File

@ -99,7 +99,7 @@ public class CustomerController extends Handler {
final User logined = super.getUser(request);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
map.put("msg", msg);
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -129,7 +129,7 @@ public class CustomerController extends Handler {
public ModelAndView today(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String ekind) throws CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -150,7 +150,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "week")
public ModelAndView week(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String ekind) throws CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -170,7 +170,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "enterprise")
public ModelAndView enterprise(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String ekind) throws CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -190,7 +190,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "personal")
public ModelAndView personal(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String ekind) throws CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -212,7 +212,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "creater")
public ModelAndView creater(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String ekind) throws CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
return request(super.createAppsTempletResponse("/apps/business/customer/index"));
}
@ -377,7 +377,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "customer")
public void expall(HttpServletRequest request, HttpServletResponse response) throws IOException, CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
// #TODO 提示没有部门
return;
}
@ -401,7 +401,7 @@ public class CustomerController extends Handler {
@Menu(type = "customer", subtype = "customer")
public void expall(ModelMap map, HttpServletRequest request, HttpServletResponse response, @Valid String q, @Valid String ekind) throws IOException, CSKefuException {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!super.esOrganFilter(request, boolQueryBuilder)) {
if (!super.esOrganFilter(request)) {
// #TODO 提示没有部门
return;
}

View File

@ -957,7 +957,7 @@ public class IMController extends Handler {
@RequestMapping("/refuse")
@Menu(type = "im", subtype = "refuse", access = true)
public void refuse(@Valid String orgi, @Valid String userid) {
OnlineUserProxy.refuseInvite(userid, orgi);
OnlineUserProxy.refuseInvite(userid);
final Date threshold = new Date(System.currentTimeMillis() - Constants.WEBIM_AGENT_INVITE_TIMEOUT);
Page<InviteRecord> inviteRecords = inviteRecordRes.findByUseridAndOrgiAndResultAndCreatetimeGreaterThan(
userid,

View File

@ -27,6 +27,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
@ -86,15 +87,15 @@ public class TenantController extends Handler {
} else {
List<OrgiSkillRel> orgiSkillRelList = orgiSkillRelRes.findBySkillidIn(
new ArrayList<>((super.getUser(request)).getAffiliates()));
List<Tenant> tenantList = null;
List<Tenant> tenantList;
if (!orgiSkillRelList.isEmpty()) {
tenantList = new ArrayList<>();
for (OrgiSkillRel orgiSkillRel : orgiSkillRelList) {
Tenant t = tenantRes.findById(orgiSkillRel.getOrgi());
if (t != null) {
tenantList.add(t);
}
tenantRes.findById(orgiSkillRel.getOrgi())
.ifPresent(tenantList::add);
}
} else {
tenantList = null;
}
map.addAttribute("tenantList", tenantList);
}
@ -183,12 +184,14 @@ public class TenantController extends Handler {
@RequestMapping("/update")
@Menu(type = "apps", subtype = "tenant", admin = true)
public ModelAndView update(HttpServletRequest request, @NonNull @Valid Tenant tenant, @RequestParam(value = "tenantpic", required = false) MultipartFile tenantpic, @Valid String skills) throws IOException {
Tenant temp = tenantRes.findById(tenant.getId());
Tenant temp = optionalById(tenant.getId());
Tenant tenanttemp = tenantRes.findByOrgidAndTenantname(super.getOrgid(request), tenant.getTenantname());
if (temp != null && tenanttemp != null && !temp.getId().equals(tenanttemp.getId())) {
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=tenantexist"));
}
tenant.setCreatetime(temp.getCreatetime());
if (temp != null) {
tenant.setCreatetime(temp.getCreatetime());
}
if (tenantpic != null && tenantpic.getOriginalFilename() != null && tenantpic.getOriginalFilename().lastIndexOf(".") > 0) {
File logoDir = new File(path, "tenantpic");
if (!logoDir.exists()) {
@ -200,7 +203,9 @@ public class TenantController extends Handler {
FileCopyUtils.copy(tenantpic.getBytes(), new File(path, fileName));
tenant.setTenantlogo(fileName);
} else {
tenant.setTenantlogo(temp.getTenantlogo());
if (temp != null) {
tenant.setTenantlogo(temp.getTenantlogo());
}
}
if (!StringUtils.isBlank(super.getUser(request).getOrgid())) {
tenant.setOrgid(super.getUser(request).getOrgid());
@ -228,9 +233,8 @@ public class TenantController extends Handler {
@RequestMapping("/delete")
@Menu(type = "apps", subtype = "tenant")
public ModelAndView delete(@Valid Tenant tenant) {
Tenant temp = tenantRes.findById(tenant.getId());
if (tenant != null) {
tenantRes.delete(temp);
tenantRes.deleteById(tenant.getId());
}
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index"));
}
@ -243,7 +247,7 @@ public class TenantController extends Handler {
(super.getUser(request)).getId(), super.getOrgi(request));
if (agentStatus == null && cache.getInservAgentUsersSizeByAgentnoAndOrgi(
super.getUser(request).getId(), super.getOrgi(request)) == 0) {
Tenant temp = tenantRes.findById(tenant.getId());
Tenant temp = optionalById(tenant.getId());
if (temp != null) {
super.getUser(request).setOrgi(temp.getId());
}
@ -251,13 +255,13 @@ public class TenantController extends Handler {
}
if (agentStatus != null) {
if (tenant.getId().equals(agentStatus.getOrgi())) {
Tenant temp = tenantRes.findById(tenant.getId());
Tenant temp = optionalById(tenant.getId());
if (temp != null) {
super.getUser(request).setOrgi(temp.getId());
}
return view;
} else {
Tenant temp = tenantRes.findById(agentStatus.getOrgi());
Tenant temp = optionalById(agentStatus.getOrgi());
return request(super.createRequestPageTempletResponse(
"redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentStatus.getOrgi() + "&currentname=" + URLEncoder.encode(
temp != null ? temp.getTenantname() : "", "UTF-8")));
@ -268,13 +272,13 @@ public class TenantController extends Handler {
super.getOrgi(request));
if (agentUser != null) {
if (tenant.getId().equals(agentUser.getOrgi())) {
Tenant temp = tenantRes.findById(tenant.getId());
Tenant temp = optionalById(tenant.getId());
if (temp != null) {
super.getUser(request).setOrgi(temp.getId());
}
return view;
} else {
Tenant temp = tenantRes.findById(agentUser.getOrgi());
Tenant temp = optionalById(agentUser.getOrgi());
return request(super.createRequestPageTempletResponse(
"redirect:/apps/tenant/index.html?msg=t0" + "&currentorgi=" + agentUser.getOrgi() + "&currentname=" + URLEncoder.encode(
temp != null ? temp.getTenantname() : "", "UTF-8")));
@ -283,4 +287,10 @@ public class TenantController extends Handler {
}
return request(super.createRequestPageTempletResponse("redirect:/apps/tenant/index.html?msg=t0"));
}
@Nullable
private Tenant optionalById(@NonNull String id) {
return tenantRes.findById(id)
.orElse(null);
}
}

View File

@ -1,130 +1,130 @@
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.interceptor;
import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.RequestLog;
import com.chatopera.cc.model.User;
import com.chatopera.cc.persistence.repository.RequestLogRepository;
import com.chatopera.cc.util.Menu;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Enumeration;
/**
* 系统访问记录
*
* @author admin
*/
public class LogIntercreptorHandler implements org.springframework.web.servlet.HandlerInterceptor {
private final static Logger logger = LoggerFactory.getLogger(LogIntercreptorHandler.class);
private static RequestLogRepository requestLogRes;
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2, ModelAndView arg3) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) arg2;
Object hander = handlerMethod.getBean();
RequestMapping obj = handlerMethod.getMethod().getAnnotation(RequestMapping.class);
if (StringUtils.isNotBlank(request.getRequestURI()) && !(request.getRequestURI().startsWith("/message/ping") || request.getRequestURI().startsWith("/res/css") || request.getRequestURI().startsWith("/error") || request.getRequestURI().startsWith("/im/"))) {
RequestLog log = new RequestLog();
log.setEndtime(new Date());
if (obj != null) {
log.setName(obj.name());
}
log.setMethodname(handlerMethod.toString());
log.setIp(request.getRemoteAddr());
if (hander != null) {
log.setClassname(hander.getClass().toString());
if (hander instanceof Handler && ((Handler) hander).getStarttime() != 0) {
log.setQuerytime(System.currentTimeMillis() - ((Handler) hander).getStarttime());
}
}
log.setUrl(request.getRequestURI());
log.setHostname(request.getRemoteHost());
log.setEndtime(new Date());
log.setType(MainContext.LogType.REQUEST.toString());
User user = (User) request.getSession(true).getAttribute(Constants.USER_SESSION_NAME);
if (user != null) {
log.setUserid(user.getId());
log.setUsername(user.getUsername());
log.setUsermail(user.getEmail());
log.setOrgi(user.getOrgi());
}
StringBuffer str = new StringBuffer();
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String paraName = names.nextElement();
if (paraName.indexOf("password") >= 0) {
str.append(paraName).append("=").append(MainUtils.encryption(request.getParameter(paraName))).append(",");
} else {
str.append(paraName).append("=").append(request.getParameter(paraName)).append(",");
}
}
Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class);
if (menu != null) {
log.setFuntype(menu.type());
log.setFundesc(menu.subtype());
log.setName(menu.name());
}
log.setParameters(str.toString());
getRequestLogRes().save(log);
}
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) {
HandlerMethod handlerMethod = (HandlerMethod) arg2;
Object hander = handlerMethod.getBean();
if (hander instanceof Handler) {
((Handler) hander).setStarttime(System.currentTimeMillis());
}
return true;
}
private static RequestLogRepository getRequestLogRes() {
if (requestLogRes == null) {
requestLogRes = MainContext.getContext().getBean(RequestLogRepository.class);
}
return requestLogRes;
}
}
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.interceptor;
import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.RequestLog;
import com.chatopera.cc.model.User;
import com.chatopera.cc.persistence.repository.RequestLogRepository;
import com.chatopera.cc.util.Menu;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Enumeration;
/**
* 系统访问记录
*
* @author admin
*/
public class LogIntercreptorHandler implements org.springframework.web.servlet.HandlerInterceptor {
private final static Logger logger = LoggerFactory.getLogger(LogIntercreptorHandler.class);
private static RequestLogRepository requestLogRes;
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2, ModelAndView arg3) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) arg2;
Object hander = handlerMethod.getBean();
RequestMapping obj = handlerMethod.getMethod().getAnnotation(RequestMapping.class);
if (StringUtils.isNotBlank(request.getRequestURI()) && !(request.getRequestURI().startsWith("/message/ping") || request.getRequestURI().startsWith("/res/css") || request.getRequestURI().startsWith("/error") || request.getRequestURI().startsWith("/im/"))) {
RequestLog log = new RequestLog();
log.setEndtime(new Date());
if (obj != null) {
log.setName(obj.name());
}
log.setMethodname(handlerMethod.toString());
log.setIp(request.getRemoteAddr());
if (hander != null) {
log.setClassname(hander.getClass().toString());
if (hander instanceof Handler && ((Handler) hander).getStartTime() != 0) {
log.setQuerytime(System.currentTimeMillis() - ((Handler) hander).getStartTime());
}
}
log.setUrl(request.getRequestURI());
log.setHostname(request.getRemoteHost());
log.setEndtime(new Date());
log.setType(MainContext.LogType.REQUEST.toString());
User user = (User) request.getSession(true).getAttribute(Constants.USER_SESSION_NAME);
if (user != null) {
log.setUserid(user.getId());
log.setUsername(user.getUsername());
log.setUsermail(user.getEmail());
log.setOrgi(user.getOrgi());
}
StringBuffer str = new StringBuffer();
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String paraName = names.nextElement();
if (paraName.indexOf("password") >= 0) {
str.append(paraName).append("=").append(MainUtils.encryption(request.getParameter(paraName))).append(",");
} else {
str.append(paraName).append("=").append(request.getParameter(paraName)).append(",");
}
}
Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class);
if (menu != null) {
log.setFuntype(menu.type());
log.setFundesc(menu.subtype());
log.setName(menu.name());
}
log.setParameters(str.toString());
getRequestLogRes().save(log);
}
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) {
HandlerMethod handlerMethod = (HandlerMethod) arg2;
Object hander = handlerMethod.getBean();
if (hander instanceof Handler) {
((Handler) hander).setStartTime(System.currentTimeMillis());
}
return true;
}
private static RequestLogRepository getRequestLogRes() {
if (requestLogRes == null) {
requestLogRes = MainContext.getContext().getBean(RequestLogRepository.class);
}
return requestLogRes;
}
}

View File

@ -1,34 +1,34 @@
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.Tenant;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface TenantRepository extends JpaRepository<Tenant, String> {
Tenant findById(String id);
List<Tenant> findByOrgid(String orgid);
Tenant findByOrgidAndTenantname(String orgid, String tenantname);
}
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.Tenant;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface TenantRepository extends JpaRepository<Tenant, String> {
// Tenant findById(String id);
List<Tenant> findByOrgid(String orgid);
Tenant findByOrgidAndTenantname(String orgid, String tenantname);
}

View File

@ -22,7 +22,6 @@ import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.model.*;
import com.chatopera.cc.persistence.es.ContactsRepository;
import com.chatopera.cc.persistence.interfaces.DataExchangeInterface;
import com.chatopera.cc.persistence.repository.*;
import com.chatopera.cc.socketio.message.OtherMessageItem;
@ -33,8 +32,6 @@ import freemarker.template.TemplateException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import javax.servlet.http.Cookie;
@ -43,7 +40,6 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.CharacterCodingException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -60,33 +56,10 @@ public class OnlineUserProxy {
private static OnlineUserHisRepository onlineUserHisRes;
private static UserTraceRepository userTraceRes;
private static OrgiSkillRelRepository orgiSkillRelRes;
private static AgentUserContactsRepository agentUserContactsRes;
private static ContactsRepository contactsRes;
private static UserProxy userProxy;
/**
* @param id
* @return
* @throws Exception
*/
public static OnlineUser user(final String orgi, final String id) {
return getOnlineUserRes().findOne(id);
}
/**
* 更新cache
*
* @param consultInvite
*/
public static void cacheConsult(final CousultInvite consultInvite) {
logger.info("[cacheConsult] snsid {}, orgi {}", consultInvite.getSnsaccountid(), consultInvite.getOrgi());
getCache().putConsultInviteByOrgi(consultInvite.getOrgi(), consultInvite);
}
/**
* @param snsid
* @param orgi
* @return
*/
public static CousultInvite consult(final String snsid, final String orgi) {
// logger.info("[consult] snsid {}, orgi {}", snsid, orgi);
@ -103,10 +76,6 @@ public class OnlineUserProxy {
/**
* 在Cache中查询OnlineUser或者从数据库中根据UserIdOrgi和Invite查询
*
* @param userid
* @param orgi
* @return
*/
public static OnlineUser onlineuser(String userid, String orgi) {
// 从Cache中查找
@ -123,13 +92,8 @@ public class OnlineUserProxy {
/**
* @param orgi
* @param ipdata
* @param invite
* @param isJudgeShare 是否判断是否共享租户
* @return
*
*/
@SuppressWarnings("unchecked")
public static List<Organ> organ(
String orgi, final IP ipdata,
final CousultInvite invite, boolean isJudgeShare) {
@ -151,7 +115,7 @@ public class OnlineUserProxy {
MainContext.SYSTEM_ORGI, (invite == null ? origOrig : invite.getOrgi())))) {
OrgiSkillRelRepository orgiSkillRelService = MainContext.getContext().getBean(
OrgiSkillRelRepository.class);
List<OrgiSkillRel> orgiSkillRelList = null;
List<OrgiSkillRel> orgiSkillRelList;
orgiSkillRelList = orgiSkillRelService.findByOrgi((invite == null ? origOrig : invite.getOrgi()));
List<Organ> skillTempList = new ArrayList<>();
if (!orgiSkillRelList.isEmpty()) {
@ -175,11 +139,13 @@ public class OnlineUserProxy {
return skillGroups;
}
List<Organ> regOrganList = new ArrayList<Organ>();
List<Organ> regOrganList = new ArrayList<>();
if (ipdata == null) {
return regOrganList;
}
for (Organ organ : skillGroups) {
if (StringUtils.isNotBlank(organ.getArea())) {
if (organ.getArea().indexOf(ipdata.getProvince()) >= 0 || organ.getArea().indexOf(
ipdata.getCity()) >= 0) {
if (organ.getArea().contains(ipdata.getProvince()) || organ.getArea().contains(ipdata.getCity())) {
regOrganList.add(organ);
}
} else {
@ -191,20 +157,17 @@ public class OnlineUserProxy {
/**
* @param orgi
* @param isJudgeShare
* @return
*
*/
@SuppressWarnings("unchecked")
public static List<Organ> organ(String orgi, boolean isJudgeShare) {
return organ(orgi, null, null, isJudgeShare);
}
private static List<AreaType> getAreaTypeList(String area, List<AreaType> areaTypeList) {
List<AreaType> atList = new ArrayList<AreaType>();
List<AreaType> atList = new ArrayList<>();
if (areaTypeList != null && areaTypeList.size() > 0) {
for (AreaType areaType : areaTypeList) {
if (StringUtils.isNotBlank(area) && area.indexOf(areaType.getId()) >= 0) {
if (StringUtils.isNotBlank(area) && area.contains(areaType.getId())) {
atList.add(areaType);
}
}
@ -212,62 +175,8 @@ public class OnlineUserProxy {
return atList;
}
/**
* 只要有一级 地区命中就就返回
*
* @param orgi
* @param ipdata
* @param topicTypeList
* @return
*/
public static List<KnowledgeType> topicType(String orgi, IP ipdata, List<KnowledgeType> topicTypeList) {
List<KnowledgeType> tempTopicTypeList = new ArrayList<KnowledgeType>();
for (KnowledgeType topicType : topicTypeList) {
if (getParentArea(ipdata, topicType, topicTypeList) != null) {
tempTopicTypeList.add(topicType);
}
}
return tempTopicTypeList;
}
/**
* @param topicType
* @param topicTypeList
* @return
*/
private static KnowledgeType getParentArea(IP ipdata, KnowledgeType topicType, List<KnowledgeType> topicTypeList) {
KnowledgeType area = null;
if (StringUtils.isNotBlank(topicType.getArea())) {
if ((topicType.getArea().indexOf(ipdata.getProvince()) >= 0 || topicType.getArea().indexOf(
ipdata.getCity()) >= 0)) {
area = topicType;
}
} else {
if (StringUtils.isNotBlank(topicType.getParentid()) && !topicType.getParentid().equals("0")) {
for (KnowledgeType temp : topicTypeList) {
if (temp.getId().equals(topicType.getParentid())) {
if (StringUtils.isNotBlank(temp.getArea())) {
if ((temp.getArea().indexOf(ipdata.getProvince()) >= 0 || temp.getArea().indexOf(
ipdata.getCity()) >= 0)) {
area = temp;
break;
} else {
break;
}
} else {
area = getParentArea(ipdata, temp, topicTypeList);
}
}
}
} else {
area = topicType;
}
}
return area;
}
public static List<Topic> topic(String orgi, List<KnowledgeType> topicTypeList, List<Topic> topicList) {
List<Topic> tempTopicList = new ArrayList<Topic>();
public static List<Topic> topic(List<KnowledgeType> topicTypeList, List<Topic> topicList) {
List<Topic> tempTopicList = new ArrayList<>();
if (topicList != null) {
for (Topic topic : topicList) {
if (StringUtils.isBlank(topic.getCate()) || Constants.DEFAULT_TYPE.equals(
@ -281,13 +190,9 @@ public class OnlineUserProxy {
/**
* 根据热点知识找到 非空的 分类
*
* @param topicTypeList
* @param topicList
* @return
*/
public static List<KnowledgeType> filterTopicType(List<KnowledgeType> topicTypeList, List<Topic> topicList) {
List<KnowledgeType> tempTopicTypeList = new ArrayList<KnowledgeType>();
List<KnowledgeType> tempTopicTypeList = new ArrayList<>();
if (topicTypeList != null) {
for (KnowledgeType knowledgeType : topicTypeList) {
boolean hasTopic = false;
@ -307,10 +212,6 @@ public class OnlineUserProxy {
/**
* 找到知识点对应的 分类
*
* @param cate
* @param topicTypeList
* @return
*/
private static KnowledgeType getTopicType(String cate, List<KnowledgeType> topicTypeList) {
KnowledgeType kt = null;
@ -325,11 +226,8 @@ public class OnlineUserProxy {
/**
* @param orgi
* @param isJudgeShare
* @return
*
*/
@SuppressWarnings("unchecked")
public static List<User> agents(String orgi, boolean isJudgeShare) {
String origOrig = orgi;
boolean isShare = false;
@ -341,10 +239,10 @@ public class OnlineUserProxy {
}
}
List<User> agentList = getCache().findOneSystemByIdAndOrgi(Constants.CACHE_AGENT + origOrig, origOrig);
List<User> agentTempList = null;
List<User> agentTempList;
if (agentList == null) {
agentList = getUserRes().findByOrgiAndAgentAndDatastatus(orgi, true, false);
agentTempList = new ArrayList<User>();
agentTempList = new ArrayList<>();
// 共享的话 查出绑定的组织
if (isShare) {
List<OrgiSkillRel> orgiSkillRelList = getOrgiSkillRelRes().findByOrgi(origOrig);
@ -375,7 +273,7 @@ public class OnlineUserProxy {
SystemConfig systemConfig = MainUtils.getSystemConfig();
if (systemConfig != null && systemConfig.isEnabletneant() && systemConfig.isTenantshare()) {
TenantRepository tenantRes = MainContext.getContext().getBean(TenantRepository.class);
Tenant tenant = tenantRes.findById(orgi);
Tenant tenant = tenantRes.findById(orgi).orElse(null);
if (tenant != null) {
List<Tenant> tenants = tenantRes.findByOrgid(tenant.getOrgid());
if (!tenants.isEmpty()) {
@ -393,73 +291,9 @@ public class OnlineUserProxy {
}
public static Contacts processContacts(
final String orgi,
Contacts contacts,
final String appid,
final String userid) {
if (contacts != null) {
if (contacts != null &&
(StringUtils.isNotBlank(contacts.getName()) ||
StringUtils.isNotBlank(contacts.getPhone()) ||
StringUtils.isNotBlank(contacts.getEmail()))) {
StringBuffer query = new StringBuffer();
query.append(contacts.getName());
if (StringUtils.isNotBlank(contacts.getPhone())) {
query.append(" OR ").append(contacts.getPhone());
}
if (StringUtils.isNotBlank(contacts.getEmail())) {
query.append(" OR ").append(contacts.getEmail());
}
Page<Contacts> contactsList = contactsRes.findByOrgi(
orgi, false, query.toString(), PageRequest.of(0, 1));
if (contactsList.getContent().size() > 0) {
contacts = contactsList.getContent().get(0);
} else {
// contactsRes.save(contacts) ; //需要增加签名验证避免随便产生垃圾信息也可以自行修改
contacts.setId(null);
}
} else {
contacts.setId(null);
}
if (contacts != null && StringUtils.isNotBlank(contacts.getId())) {
if (!getAgentUserContactsRes().findOneByUseridAndOrgi(userid, orgi).isPresent()) {
AgentUserContacts agentUserContacts = new AgentUserContacts();
agentUserContacts.setAppid(appid);
agentUserContacts.setChannel(MainContext.ChannelType.WEBIM.toString());
agentUserContacts.setContactsid(contacts.getId());
agentUserContacts.setUserid(userid);
agentUserContacts.setOrgi(orgi);
agentUserContacts.setCreatetime(new Date());
agentUserContactsRes.save(agentUserContacts);
}
} else if (StringUtils.isNotBlank(userid)) {
Optional<AgentUserContacts> agentUserContactOpt = agentUserContactsRes.findOneByUseridAndOrgi(
userid, orgi);
if (agentUserContactOpt.isPresent()) {
contacts = getContactsRes().findOne(agentUserContactOpt.get().getContactsid());
}
}
}
return contacts;
}
/**
* 创建OnlineUser并上线
* 根据user判断追踪在浏览器里用fingerprint2生成的ID作为唯一标识
*
* @param user
* @param orgi
* @param sessionid
* @param optype
* @param request
* @param channel
* @param appid
* @param contacts
* @param invite
* @return
* @throws CharacterCodingException
*/
public static OnlineUser online(
final User user,
@ -508,7 +342,7 @@ public class OnlineUserProxy {
onlineUser.setOlduser("1");
}
onlineUser.setMobile(MobileDevice.isMobile(request
.getHeader("User-Agent")) ? "1" : "0");
.getHeader("User-Agent")) ? "1" : "0");
// onlineUser.setSource(user.getId());
@ -546,10 +380,10 @@ public class OnlineUserProxy {
onlineUser.setCity(ipdata.getCity());
onlineUser.setIsp(ipdata.getIsp());
onlineUser.setRegion(ipdata.toString() + ""
+ ip + "");
+ ip + "");
onlineUser.setDatestr(new SimpleDateFormat("yyyMMdd")
.format(now));
.format(now));
onlineUser.setHostname(ip);
onlineUser.setSessionid(sessionid);
@ -620,7 +454,7 @@ public class OnlineUserProxy {
}
// 完成获取及更新OnlineUser, 将信息加入缓存
if (onlineUser != null && StringUtils.isNotBlank(onlineUser.getUserid())) {
if (StringUtils.isNotBlank(onlineUser.getUserid())) {
// logger.info(
// "[online] onlineUser id {}, status {}, invite status {}", onlineUser.getId(),
// onlineUser.getStatus(), onlineUser.getInvitestatus());
@ -632,9 +466,7 @@ public class OnlineUserProxy {
}
/**
* @param request
* @param key
* @return
*
*/
public static String getCookie(HttpServletRequest request, String key) {
Cookie data = null;
@ -650,9 +482,7 @@ public class OnlineUserProxy {
}
/**
* @param user
* @param orgi
* @throws Exception
*
*/
public static void offline(String user, String orgi) {
if (MainContext.getContext() != null) {
@ -676,9 +506,6 @@ public class OnlineUserProxy {
/**
* 设置onlineUser为离线
*
* @param onlineUser
* @throws Exception
*/
public static void offline(OnlineUser onlineUser) {
if (onlineUser != null) {
@ -687,12 +514,10 @@ public class OnlineUserProxy {
}
/**
* @param user
* @param orgi
* @throws Exception
*
*/
public static void refuseInvite(final String user, final String orgi) {
OnlineUser onlineUser = getOnlineUserRes().findOne(user);
public static void refuseInvite(final String user) {
OnlineUser onlineUser = getOnlineUserRes().findById(user).orElse(null);
if (onlineUser != null) {
onlineUser.setInvitestatus(MainContext.OnlineUserInviteStatus.REFUSE.toString());
onlineUser.setRefusetimes(onlineUser.getRefusetimes() + 1);
@ -701,7 +526,7 @@ public class OnlineUserProxy {
}
public static String unescape(String src) {
StringBuffer tmp = new StringBuffer();
StringBuilder tmp = new StringBuilder();
try {
tmp.append(java.net.URLDecoder.decode(src, "UTF-8"));
} catch (UnsupportedEncodingException e) {
@ -712,13 +537,13 @@ public class OnlineUserProxy {
}
public static String getKeyword(String url) {
Map<String, String[]> values = new HashMap<String, String[]>();
Map<String, String[]> values = new HashMap<>();
try {
OnlineUserUtils.parseParameters(values, url, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StringBuffer strb = new StringBuffer();
StringBuilder strb = new StringBuilder();
String[] data = values.get("q");
if (data != null) {
for (String v : data) {
@ -741,9 +566,6 @@ public class OnlineUserProxy {
/**
* 发送邀请
*
* @param userid
* @throws Exception
*/
public static void sendWebIMClients(String userid, String msg) throws Exception {
// logger.info("[sendWebIMClients] userId {}, msg {}", userid, msg);
@ -766,14 +588,14 @@ public class OnlineUserProxy {
}
}
public static void resetHotTopic(DataExchangeInterface dataExchange, User user, String orgi, String aiid) {
public static void resetHotTopic(DataExchangeInterface dataExchange, String orgi, String aiid) {
getCache().deleteSystembyIdAndOrgi("xiaoeTopic", orgi);
cacheHotTopic(dataExchange, user, orgi, aiid);
cacheHotTopic(dataExchange, orgi, aiid);
}
@SuppressWarnings("unchecked")
public static List<Topic> cacheHotTopic(DataExchangeInterface dataExchange, User user, String orgi, String aiid) {
List<Topic> topicList = null;
public static List<Topic> cacheHotTopic(DataExchangeInterface dataExchange, String orgi, String aiid) {
List<Topic> topicList;
if ((topicList = getCache().findOneSystemListByIdAndOrgi("xiaoeTopic", orgi)) == null) {
topicList = (List<Topic>) dataExchange.getListDataByIdAndOrgi(aiid, null, orgi);
getCache().putSystemListByIdAndOrgi("xiaoeTopic", orgi, topicList);
@ -781,16 +603,16 @@ public class OnlineUserProxy {
return topicList;
}
public static void resetHotTopicType(DataExchangeInterface dataExchange, User user, String orgi, String aiid) {
public static void resetHotTopicType(DataExchangeInterface dataExchange, String orgi, String aiid) {
if (getCache().existSystemByIdAndOrgi("xiaoeTopicType" + "." + orgi, orgi)) {
getCache().deleteSystembyIdAndOrgi("xiaoeTopicType" + "." + orgi, orgi);
}
cacheHotTopicType(dataExchange, user, orgi, aiid);
cacheHotTopicType(dataExchange, orgi, aiid);
}
@SuppressWarnings("unchecked")
public static List<KnowledgeType> cacheHotTopicType(DataExchangeInterface dataExchange, User user, String orgi, String aiid) {
List<KnowledgeType> topicTypeList = null;
public static List<KnowledgeType> cacheHotTopicType(DataExchangeInterface dataExchange, String orgi, String aiid) {
List<KnowledgeType> topicTypeList;
if ((topicTypeList = getCache().findOneSystemListByIdAndOrgi("xiaoeTopicType" + "." + orgi, orgi)) == null) {
topicTypeList = (List<KnowledgeType>) dataExchange.getListDataByIdAndOrgi(aiid, null, orgi);
getCache().putSystemListByIdAndOrgi("xiaoeTopicType" + "." + orgi, orgi, topicTypeList);
@ -799,8 +621,8 @@ public class OnlineUserProxy {
}
@SuppressWarnings("unchecked")
public static List<SceneType> cacheSceneType(DataExchangeInterface dataExchange, User user, String orgi) {
List<SceneType> sceneTypeList = null;
public static List<SceneType> cacheSceneType(DataExchangeInterface dataExchange, String orgi) {
List<SceneType> sceneTypeList;
if ((sceneTypeList = getCache().findOneSystemListByIdAndOrgi("xiaoeSceneType", orgi)) == null) {
sceneTypeList = (List<SceneType>) dataExchange.getListDataByIdAndOrgi(null, null, orgi);
getCache().putSystemListByIdAndOrgi("xiaoeSceneType", orgi, sceneTypeList);
@ -808,11 +630,10 @@ public class OnlineUserProxy {
return sceneTypeList;
}
@SuppressWarnings("unchecked")
public static boolean filterSceneType(String cate, String orgi, IP ipdata) {
boolean result = false;
List<SceneType> sceneTypeList = cacheSceneType(
(DataExchangeInterface) MainContext.getContext().getBean("scenetype"), null, orgi);
(DataExchangeInterface) MainContext.getContext().getBean("scenetype"), orgi);
List<AreaType> areaTypeList = getCache().findOneSystemListByIdAndOrgi(
Constants.CSKEFU_SYSTEM_AREA, MainContext.SYSTEM_ORGI);
if (sceneTypeList != null && cate != null && !Constants.DEFAULT_TYPE.equals(cate)) {
@ -823,8 +644,7 @@ public class OnlineUserProxy {
List<AreaType> atList = getAreaTypeList(
sceneType.getArea(), areaTypeList); //找到技能组配置的地区信息
for (AreaType areaType : atList) {
if (areaType.getArea().indexOf(ipdata.getProvince()) >= 0 || areaType.getArea().indexOf(
ipdata.getCity()) >= 0) {
if (areaType.getArea().contains(ipdata.getProvince()) || areaType.getArea().contains(ipdata.getCity())) {
result = true;
break;
}
@ -851,7 +671,7 @@ public class OnlineUserProxy {
orgi);
if (StringUtils.isNotBlank(sessionConfig.getOqrsearchurl())) {
Template templet = MainUtils.getTemplate(sessionConfig.getOqrsearchinput());
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("q", q);
values.put("user", user);
param = MainUtils.getTemplet(templet.getTemplettext(), values);
@ -862,7 +682,7 @@ public class OnlineUserProxy {
Template templet = MainUtils.getTemplate(sessionConfig.getOqrsearchoutput());
@SuppressWarnings("unchecked")
Map<String, Object> jsonData = objectMapper.readValue(result, Map.class);
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("q", q);
values.put("user", user);
values.put("data", jsonData);
@ -875,12 +695,12 @@ public class OnlineUserProxy {
return otherMessageItemList;
}
public static OtherMessageItem suggestdetail(AiConfig aiCofig, String id, String orgi, User user) throws IOException, TemplateException {
public static OtherMessageItem suggestdetail(AiConfig aiCofig, String id, User user) throws IOException, TemplateException {
OtherMessageItem otherMessageItem = null;
String param = "";
if (StringUtils.isNotBlank(aiCofig.getOqrdetailinput())) {
Template templet = MainUtils.getTemplate(aiCofig.getOqrdetailinput());
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("id", id);
values.put("user", user);
param = MainUtils.getTemplet(templet.getTemplettext(), values);
@ -891,7 +711,7 @@ public class OnlineUserProxy {
Template templet = MainUtils.getTemplate(aiCofig.getOqrdetailoutput());
@SuppressWarnings("unchecked")
Map<String, Object> jsonData = objectMapper.readValue(result, Map.class);
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("id", id);
values.put("user", user);
values.put("data", jsonData);
@ -911,7 +731,7 @@ public class OnlineUserProxy {
orgi);
if (StringUtils.isNotBlank(sessionConfig.getOqrdetailinput())) {
Template templet = MainUtils.getTemplate(sessionConfig.getOqrdetailinput());
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("id", id);
values.put("user", user);
param = MainUtils.getTemplet(templet.getTemplettext(), values);
@ -922,7 +742,7 @@ public class OnlineUserProxy {
Template templet = MainUtils.getTemplate(sessionConfig.getOqrdetailoutput());
@SuppressWarnings("unchecked")
Map<String, Object> jsonData = objectMapper.readValue(result, Map.class);
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
values.put("id", id);
values.put("user", user);
values.put("data", jsonData);
@ -942,10 +762,6 @@ public class OnlineUserProxy {
/**
* 创建Skype联系人的onlineUser记录
*
* @param contact
* @param logined
* @return
*/
public static OnlineUser createNewOnlineUserWithContactAndChannel(final Contacts contact, final User logined, final String channel) {
final Date now = new Date();
@ -970,21 +786,6 @@ public class OnlineUserProxy {
}
private static AgentUserContactsRepository getAgentUserContactsRes() {
if (agentUserContactsRes == null) {
agentUserContactsRes = MainContext.getContext().getBean(AgentUserContactsRepository.class);
}
return agentUserContactsRes;
}
private static ContactsRepository getContactsRes() {
if (contactsRes == null) {
contactsRes = MainContext.getContext().getBean(ContactsRepository.class);
}
return contactsRes;
}
private static OnlineUserRepository getOnlineUserRes() {
if (onlineUserRes == null) {