From 75f7ce79d4cefaf67d09d1585beb448ad23176d7 Mon Sep 17 00:00:00 2001 From: "dengchao@xgtl" <2325690622@qq.com> Date: Thu, 16 Apr 2020 14:04:04 +0800 Subject: [PATCH] Fix PbxHostRepository related class --- .../callcenter/CallCenterAclController.java | 214 ++++---- .../callcenter/CallCenterController.java | 353 +++++++------ .../CallCenterExtentionController.java | 496 +++++++++--------- .../callcenter/CallCenterIvrController.java | 214 ++++---- .../callcenter/CallCenterMediaController.java | 324 ++++++------ .../CallCenterResourceController.java | 268 +++++----- .../CallCenterRouterController.java | 271 +++++----- .../CallCenterSipTrunkController.java | 306 +++++------ .../callcenter/CallCenterSkillController.java | 375 ++++++------- .../controller/apps/ExtentionController.java | 377 +++++++------ .../repository/PbxHostRepository.java | 69 +-- 11 files changed, 1648 insertions(+), 1619 deletions(-) diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java index 4893448e..952579a6 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterAclController.java @@ -1,106 +1,108 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Acl; -import com.chatopera.cc.persistence.repository.AclRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterAclController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private AclRepository aclRes ; - - @RequestMapping(value = "/acl") - @Menu(type = "callcenter" , subtype = "callcenteracl" , access = false , admin = true) - public ModelAndView acl(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("aclList" , aclRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/index")); - } - - @RequestMapping(value = "/acl/add") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acladd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/add")); - } - - @RequestMapping(value = "/acl/save") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView aclsave(ModelMap map , HttpServletRequest request , @Valid Acl acl) { - if(!StringUtils.isBlank(acl.getName())){ - int count = aclRes.countByNameAndOrgi(acl.getName(), super.getOrgi(request)) ; - if(count == 0){ - acl.setOrgi(super.getOrgi(request)); - acl.setCreater(super.getUser(request).getId()); - aclRes.save(acl) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+acl.getHostid())); - } - - @RequestMapping(value = "/acl/edit") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acledit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("acl" , aclRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/edit")); - } - - @RequestMapping(value = "/acl/update") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid Acl acl) { - if(!StringUtils.isBlank(acl.getId())){ - Acl oldAcl = aclRes.findByIdAndOrgi(acl.getId(), super.getOrgi(request)) ; - if(oldAcl!=null){ - oldAcl.setName(acl.getName()); - oldAcl.setDefaultvalue(acl.getDefaultvalue()); - oldAcl.setStrategy(acl.getStrategy()); - aclRes.save(oldAcl); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+acl.getHostid())); - } - - @RequestMapping(value = "/acl/delete") - @Menu(type = "callcenter" , subtype = "acl" , access = false , admin = true) - public ModelAndView acldelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - aclRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid="+hostid)); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Acl; +import com.chatopera.cc.persistence.repository.AclRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterAclController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final AclRepository aclRes; + + @RequestMapping(value = "/acl") + @Menu(type = "callcenter", subtype = "callcenteracl", admin = true) + public ModelAndView acl(ModelMap map, HttpServletRequest request, @Valid String hostid) { + if (!StringUtils.isBlank(hostid)) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("aclList", aclRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/index")); + } + + @RequestMapping(value = "/acl/add") + @Menu(type = "callcenter", subtype = "acl", admin = true) + public ModelAndView acladd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/add")); + } + + @RequestMapping(value = "/acl/save") + @Menu(type = "callcenter", subtype = "acl", admin = true) + public ModelAndView aclsave(HttpServletRequest request, @Valid Acl acl) { + if (!StringUtils.isBlank(acl.getName())) { + int count = aclRes.countByNameAndOrgi(acl.getName(), super.getOrgi(request)); + if (count == 0) { + acl.setOrgi(super.getOrgi(request)); + acl.setCreater(super.getUser(request).getId()); + aclRes.save(acl); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid=" + acl.getHostid())); + } + + @RequestMapping(value = "/acl/edit") + @Menu(type = "callcenter", subtype = "acl", admin = true) + public ModelAndView acledit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("acl", aclRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/acl/edit")); + } + + @RequestMapping(value = "/acl/update") + @Menu(type = "callcenter", subtype = "acl", admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @Valid Acl acl) { + if (!StringUtils.isBlank(acl.getId())) { + Acl oldAcl = aclRes.findByIdAndOrgi(acl.getId(), super.getOrgi(request)); + if (oldAcl != null) { + oldAcl.setName(acl.getName()); + oldAcl.setDefaultvalue(acl.getDefaultvalue()); + oldAcl.setStrategy(acl.getStrategy()); + aclRes.save(oldAcl); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid=" + acl.getHostid())); + } + + @RequestMapping(value = "/acl/delete") + @Menu(type = "callcenter", subtype = "acl", admin = true) + public ModelAndView acldelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + aclRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/acl.html?hostid=" + hostid)); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java index 4950e0e9..0d7b41a6 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterController.java @@ -1,173 +1,180 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.persistence.interfaces.CallCenterInterface; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @RequestMapping(value = "/index") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String msg) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); - - for (PbxHost pbxHost : pbxHostList) { - if (callCenterImpl != null) { - pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); - } - } - } - map.addAttribute("pbxHostList", pbxHostList); - return request(super.createAdminTempletResponse("/admin/callcenter/index")); - } - - @RequestMapping(value = "/pbxhost") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhost(ModelMap map, HttpServletRequest request) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); - - for (PbxHost pbxHost : pbxHostList) { - if (callCenterImpl != null) { - pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); - } - } - } - map.addAttribute("pbxHostList", pbxHostList); - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/index")); - } - - @RequestMapping(value = "/pbxhost/add") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostadd(ModelMap map, HttpServletRequest request) { - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/add")); - } - - @RequestMapping(value = "/pbxhost/save") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostsave(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) { - ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - String msg = null; - if (!StringUtils.isBlank(pbxHost.getName())) { - int count = pbxHostRes.countByHostnameAndOrgi(pbxHost.getHostname(), super.getOrgi(request)); - if (count == 0) { - pbxHost.setOrgi(super.getOrgi(request)); - pbxHost.setCreater(super.getUser(request).getId()); - pbxHostRes.save(pbxHost); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - try { - callCenterImpl.init(pbxHost); - } catch (Exception ex) { - msg = ex.getMessage(); - ex.printStackTrace(); - } - } - } - } - } - if (!StringUtils.isBlank(msg)) { - view = request( - super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); - } - return view; - } - - @RequestMapping(value = "/pbxhost/edit") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostedit(ModelMap map, HttpServletRequest request, @Valid String id) { - map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(id, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/edit")); - } - - @RequestMapping(value = "/pbxhost/update") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView pbxhostupdate(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) { - ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - String msg = null; - if (!StringUtils.isBlank(pbxHost.getId())) { - PbxHost destHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); - destHost.setHostname(pbxHost.getHostname()); - destHost.setIpaddr(pbxHost.getIpaddr()); - destHost.setName(pbxHost.getName()); - destHost.setPort(pbxHost.getPort()); - if (!StringUtils.isBlank(pbxHost.getPassword())) { - destHost.setPassword(pbxHost.getPassword()); - } - pbxHostRes.save(destHost); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - try { - callCenterImpl.init(destHost); - } catch (Exception ex) { - msg = ex.getMessage(); - ex.printStackTrace(); - } - } - } - } - if (!StringUtils.isBlank(msg)) { - view = request( - super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); - } - return view; - } - - @RequestMapping(value = "/pbxhost/delete") - @Menu(type = "callcenter", subtype = "pbxhost", access = false, admin = true) - public ModelAndView mediadelete(ModelMap map, HttpServletRequest request, @Valid String id) { - if (!StringUtils.isBlank(id)) { - pbxHostRes.delete(id); - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - if (callCenterImpl != null) { - callCenterImpl.remove(id); - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.basic.Constants; +import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.persistence.interfaces.CallCenterInterface; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @RequestMapping(value = "/index") + @Menu(type = "callcenter", subtype = "callcenter", admin = true) + public ModelAndView index(ModelMap map, HttpServletRequest request) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); + + for (PbxHost pbxHost : pbxHostList) { + //noinspection ConstantConditions + if (callCenterImpl != null) { + pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); + } + } + } + map.addAttribute("pbxHostList", pbxHostList); + return request(super.createAdminTempletResponse("/admin/callcenter/index")); + } + + @RequestMapping(value = "/pbxhost") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView pbxhost(ModelMap map, HttpServletRequest request) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean("callcenter"); + + for (PbxHost pbxHost : pbxHostList) { + //noinspection ConstantConditions + if (callCenterImpl != null) { + pbxHost.setConnected(callCenterImpl.connected(pbxHost.getId())); + } + } + } + map.addAttribute("pbxHostList", pbxHostList); + return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/index")); + } + + @RequestMapping(value = "/pbxhost/add") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView pbxhostadd() { + return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/add")); + } + + @RequestMapping(value = "/pbxhost/save") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView pbxhostsave(HttpServletRequest request, @Valid PbxHost pbxHost) { + ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); + String msg = null; + if (!StringUtils.isBlank(pbxHost.getName())) { + int count = pbxHostRes.countByHostnameAndOrgi(pbxHost.getHostname(), super.getOrgi(request)); + if (count == 0) { + pbxHost.setOrgi(super.getOrgi(request)); + pbxHost.setCreater(super.getUser(request).getId()); + pbxHostRes.save(pbxHost); + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( + "callcenter"); + //noinspection ConstantConditions + if (callCenterImpl != null) { + try { + callCenterImpl.init(pbxHost); + } catch (Exception ex) { + msg = ex.getMessage(); + ex.printStackTrace(); + } + } + } + } + } + if (!StringUtils.isBlank(msg)) { + view = request( + super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); + } + return view; + } + + @RequestMapping(value = "/pbxhost/edit") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView pbxhostedit(ModelMap map, HttpServletRequest request, @Valid String id) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(id, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/pbxhost/edit")); + } + + @RequestMapping(value = "/pbxhost/update") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @Valid PbxHost pbxHost) { + ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); + String msg = null; + if (!StringUtils.isBlank(pbxHost.getId())) { + PbxHost destHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); + destHost.setHostname(pbxHost.getHostname()); + destHost.setIpaddr(pbxHost.getIpaddr()); + destHost.setName(pbxHost.getName()); + destHost.setPort(pbxHost.getPort()); + if (!StringUtils.isBlank(pbxHost.getPassword())) { + destHost.setPassword(pbxHost.getPassword()); + } + pbxHostRes.save(destHost); + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( + "callcenter"); + //noinspection ConstantConditions + if (callCenterImpl != null) { + try { + callCenterImpl.init(destHost); + } catch (Exception ex) { + msg = ex.getMessage(); + ex.printStackTrace(); + } + } + } + } + if (!StringUtils.isBlank(msg)) { + view = request( + super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html?msg=" + msg)); + } + return view; + } + + @RequestMapping(value = "/pbxhost/delete") + @Menu(type = "callcenter", subtype = "pbxhost", admin = true) + public ModelAndView mediadelete(@Valid String id) { + if (!StringUtils.isBlank(id)) { + pbxHostRes.deleteById(id); + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( + "callcenter"); + //noinspection ConstantConditions + if (callCenterImpl != null) { + callCenterImpl.remove(id); + } + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/pbxhost.html")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java index b8f805a6..b8bf9b39 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterExtentionController.java @@ -1,248 +1,248 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.User; -import com.chatopera.cc.persistence.repository.*; -import com.chatopera.cc.proxy.CallcenterOutboundProxy; -import com.chatopera.cc.util.Menu; -import com.chatopera.cc.util.freeswitch.model.CallCenterAgent; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.Date; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterExtentionController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private SipTrunkRepository sipTrunkRes; - - @Autowired - private MediaRepository mediaRes; - - @Autowired - private ServiceAiRepository serviceAiRes; - - @Autowired - private ProductRepository productRes; - - @Autowired - private QueSurveyProcessRepository queSurveyProcessRes; - - @Autowired - private Cache cache; - - - @RequestMapping(value = "/extention") - @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) - public ModelAndView extention(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/index")); - } - - private PbxHost getPbxHost(List pbxHostList, String hostid) { - PbxHost pbxHost = pbxHostList.get(0); - if (StringUtils.isNotBlank(hostid)) { - for (PbxHost pbx : pbxHostList) { - if (pbx.getId().equals(hostid)) { - pbxHost = pbx; - break; - } - } - } - return pbxHost; - } - - @RequestMapping(value = "/extention/add") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/add")); - } - - @RequestMapping(value = "/extention/save") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionsave(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getExtention()) && StringUtils.isNotBlank(extention.getPassword())) { - String[] extstr = extention.getExtention().split("[,, ]"); - int extnum = 0; - for (String ext : extstr) { - if (ext.matches("[\\d]{3,8}")) { //分机号码最少3位数字 - createNewExtention(ext, super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); - } else { - String[] ph = ext.split("[~-]"); - if (ph.length == 2 && ph[0].matches("[\\d]{3,8}") && ph[1].matches("[\\d]{3,8}") && ph[0].length() == ph[1].length()) { - int start = Integer.parseInt(ph[0]); - int end = Integer.parseInt(ph[1]); - - for (int i = start; i <= end && extnum < 100; i++) { //最大一次批量生产的 分机号不超过100个 - createNewExtention(String.valueOf(i), super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); - } - } - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - private Extention createNewExtention(String num, User user, String hostid, String password, String orgi, Extention src) { - Extention extno = new Extention(); - extno.setExtention(num); - extno.setOrgi(orgi); - extno.setCreater(user.getId()); - extno.setHostid(hostid); - extno.setPassword(password); - - extno.setPlaynum(src.isPlaynum()); - extno.setCallout(src.isCallout()); - extno.setRecord(src.isRecord()); - extno.setExtype(src.getExtype()); - extno.setMediapath(src.getMediapath()); - - extno.setSiptrunk(src.getSiptrunk()); - extno.setEnablewebrtc(src.isEnablewebrtc()); - int count = extentionRes.countByExtentionAndHostidAndOrgi(extno.getExtention(), hostid, orgi); - if (count == 0) { - extentionRes.save(extno); - } - return extno; - } - - @RequestMapping(value = "/extention/edit") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/edit")); - } - - @RequestMapping(value = "/extention/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionupdate(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getId())) { - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); - if (ext != null) { -// ext.setExtention(extention.getExtention());//分机号不能修改 - if (StringUtils.isNotBlank(extention.getPassword())) { - ext.setPassword(extention.getPassword()); - } - ext.setPlaynum(extention.isPlaynum()); - ext.setCallout(extention.isCallout()); - ext.setRecord(extention.isRecord()); - ext.setExtype(extention.getExtype()); - ext.setSubtype(extention.getSubtype()); - ext.setDescription(extention.getDescription()); - - ext.setMediapath(extention.getMediapath()); - - ext.setSiptrunk(extention.getSiptrunk()); - ext.setEnablewebrtc(extention.isEnablewebrtc()); - - ext.setUpdatetime(new Date()); - extentionRes.save(ext); - - List callOutAgentList = CallcenterOutboundProxy.extention(ext.getExtention()); - for (CallCenterAgent callOutAgent : callOutAgentList) { - callOutAgent.setSiptrunk(ext.getSiptrunk()); - cache.putCallCenterAgentByIdAndOrgi(callOutAgent.getUserid(), callOutAgent.getOrgi(), callOutAgent); - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - @RequestMapping(value = "/extention/ivr") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView ivr(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - - map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); - map.put("queList", queSurveyProcessRes.findByOrgi(super.getOrgi(request))); - map.put("productList", productRes.findByOrgi(super.getOrgi(request))); - - return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/ivr")); - } - - @RequestMapping(value = "/extention/ivr/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView ivrupdate(ModelMap map, HttpServletRequest request, @Valid Extention extention) { - if (StringUtils.isNotBlank(extention.getId())) { - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); - if (ext != null) { - - ext.setEnableai(extention.getEnableai()); - ext.setAiid(extention.getAiid()); - ext.setSceneid(extention.getSceneid()); - ext.setWelcomemsg(extention.getWelcomemsg()); - ext.setWaitmsg(extention.getWaitmsg()); - ext.setTipmessage(extention.getTipmessage()); - - ext.setAitype(extention.getAitype()); - ext.setBustype(extention.getBustype()); - ext.setProid(extention.getProid()); - ext.setQueid(extention.getQueid()); - - extentionRes.save(ext); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); - } - - @RequestMapping(value = "/extention/delete") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentiondelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - if (StringUtils.isNotBlank(id)) { - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + hostid)); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.cache.Cache; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Extention; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.model.User; +import com.chatopera.cc.persistence.repository.*; +import com.chatopera.cc.proxy.CallcenterOutboundProxy; +import com.chatopera.cc.util.Menu; +import com.chatopera.cc.util.freeswitch.model.CallCenterAgent; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Date; +import java.util.List; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterExtentionController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final ExtentionRepository extentionRes; + + @NonNull + private final SipTrunkRepository sipTrunkRes; + + @NonNull + private final MediaRepository mediaRes; + + @NonNull + private final ServiceAiRepository serviceAiRes; + + @NonNull + private final ProductRepository productRes; + + @NonNull + private final QueSurveyProcessRepository queSurveyProcessRes; + + @NonNull + private final Cache cache; + + + @RequestMapping(value = "/extention") + @Menu(type = "callcenter", subtype = "callcenterresource", admin = true) + public ModelAndView extention(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + PbxHost pbxHost; + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); + map.addAttribute("extentionList", extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/index")); + } + + private PbxHost getPbxHost(List pbxHostList, String hostid) { + PbxHost pbxHost = pbxHostList.get(0); + if (StringUtils.isNotBlank(hostid)) { + for (PbxHost pbx : pbxHostList) { + if (pbx.getId().equals(hostid)) { + pbxHost = pbx; + break; + } + } + } + return pbxHost; + } + + @RequestMapping(value = "/extention/add") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + + map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + + map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/add")); + } + + @RequestMapping(value = "/extention/save") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionsave(HttpServletRequest request, @Valid Extention extention) { + if (StringUtils.isNotBlank(extention.getExtention()) && StringUtils.isNotBlank(extention.getPassword())) { + String[] extstr = extention.getExtention().split("[,, ]"); + for (String ext : extstr) { + if (ext.matches("[\\d]{3,8}")) { //分机号码最少3位数字 + createNewExtention(ext, super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); + } else { + String[] ph = ext.split("[~-]"); + if (ph.length == 2 && ph[0].matches("[\\d]{3,8}") && ph[1].matches("[\\d]{3,8}") && ph[0].length() == ph[1].length()) { + int start = Integer.parseInt(ph[0]); + int end = Integer.parseInt(ph[1]); + + for (int i = start; i <= end; i++) { //最大一次批量生产的 分机号不超过100个 + createNewExtention(String.valueOf(i), super.getUser(request), extention.getHostid(), extention.getPassword(), super.getOrgi(request), extention); + } + } + } + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); + } + + private void createNewExtention(String num, User user, String hostid, String password, String orgi, Extention src) { + Extention extno = new Extention(); + extno.setExtention(num); + extno.setOrgi(orgi); + extno.setCreater(user.getId()); + extno.setHostid(hostid); + extno.setPassword(password); + + extno.setPlaynum(src.isPlaynum()); + extno.setCallout(src.isCallout()); + extno.setRecord(src.isRecord()); + extno.setExtype(src.getExtype()); + extno.setMediapath(src.getMediapath()); + + extno.setSiptrunk(src.getSiptrunk()); + extno.setEnablewebrtc(src.isEnablewebrtc()); + int count = extentionRes.countByExtentionAndHostidAndOrgi(extno.getExtention(), hostid, orgi); + if (count == 0) { + extentionRes.save(extno); + } + } + + @RequestMapping(value = "/extention/edit") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + + return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/edit")); + } + + @RequestMapping(value = "/extention/update") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionupdate(HttpServletRequest request, @Valid Extention extention) { + if (StringUtils.isNotBlank(extention.getId())) { + Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); + if (ext != null) { +// ext.setExtention(extention.getExtention());//分机号不能修改 + if (StringUtils.isNotBlank(extention.getPassword())) { + ext.setPassword(extention.getPassword()); + } + ext.setPlaynum(extention.isPlaynum()); + ext.setCallout(extention.isCallout()); + ext.setRecord(extention.isRecord()); + ext.setExtype(extention.getExtype()); + ext.setSubtype(extention.getSubtype()); + ext.setDescription(extention.getDescription()); + + ext.setMediapath(extention.getMediapath()); + + ext.setSiptrunk(extention.getSiptrunk()); + ext.setEnablewebrtc(extention.isEnablewebrtc()); + + ext.setUpdatetime(new Date()); + extentionRes.save(ext); + + List callOutAgentList = CallcenterOutboundProxy.extention(ext.getExtention()); + for (CallCenterAgent callOutAgent : callOutAgentList) { + callOutAgent.setSiptrunk(ext.getSiptrunk()); + cache.putCallCenterAgentByIdAndOrgi(callOutAgent.getUserid(), callOutAgent.getOrgi(), callOutAgent); + } + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); + } + + @RequestMapping(value = "/extention/ivr") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView ivr(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.put("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + + map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); + map.put("queList", queSurveyProcessRes.findByOrgi(super.getOrgi(request))); + map.put("productList", productRes.findByOrgi(super.getOrgi(request))); + + return request(super.createRequestPageTempletResponse("/admin/callcenter/extention/ivr")); + } + + @RequestMapping(value = "/extention/ivr/update") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView ivrupdate(HttpServletRequest request, @Valid Extention extention) { + if (StringUtils.isNotBlank(extention.getId())) { + Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); + if (ext != null) { + + ext.setEnableai(extention.getEnableai()); + ext.setAiid(extention.getAiid()); + ext.setSceneid(extention.getSceneid()); + ext.setWelcomemsg(extention.getWelcomemsg()); + ext.setWaitmsg(extention.getWaitmsg()); + ext.setTipmessage(extention.getTipmessage()); + + ext.setAitype(extention.getAitype()); + ext.setBustype(extention.getBustype()); + ext.setProid(extention.getProid()); + ext.setQueid(extention.getQueid()); + + extentionRes.save(ext); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + extention.getHostid())); + } + + @RequestMapping(value = "/extention/delete") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentiondelete(@Valid String id, @Valid String hostid) { + if (StringUtils.isNotBlank(id)) { + extentionRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/extention.html?hostid=" + hostid)); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java index 3f5e9834..2c6ee16e 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterIvrController.java @@ -1,106 +1,108 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.IvrMenuRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterIvrController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private ExtentionRepository extentionRes ; - - @Autowired - private IvrMenuRepository ivrMenuRes; - - @RequestMapping(value = "/ivr") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView ivr(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("ivrList" , extentionRes.findByExtypeAndOrgi("ivr", super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/index")); - } - - @RequestMapping(value = "/ivr/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/edit")); - } - - @RequestMapping(value = "/ivr/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionupdate(ModelMap map , HttpServletRequest request , @Valid Extention extention) { - if(!StringUtils.isBlank(extention.getId())){ - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)) ; - ext.setExtention(extention.getExtention()); - ext.setDescription(extention.getDescription()); - extentionRes.save(ext) ; - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid="+extention.getHostid())); - } - - - @RequestMapping(value = "/ivr/delete") - @Menu(type = "callcenter" , subtype = "ivr" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid="+hostid)); - } - - @RequestMapping(value = "/ivr/design") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView design(ModelMap map , HttpServletRequest request , @Valid String hostid , @Valid String id) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.addAttribute("ivrMenuList" , ivrMenuRes.findByExtentionidAndHostidAndOrgi(id, hostid, super.getOrgi(request))); - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/design")); - } - - @RequestMapping(value = "/ivr/menu/add") - @Menu(type = "callcenter" , subtype = "callcenterivr" , access = false , admin = true) - public ModelAndView ivrmenuadd(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid , @Valid String parentid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/menuadd")); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Extention; +import com.chatopera.cc.persistence.repository.ExtentionRepository; +import com.chatopera.cc.persistence.repository.IvrMenuRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterIvrController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final ExtentionRepository extentionRes; + + @NonNull + private final IvrMenuRepository ivrMenuRes; + + @RequestMapping(value = "/ivr") + @Menu(type = "callcenter", subtype = "callcenterivr", admin = true) + public ModelAndView ivr(ModelMap map, HttpServletRequest request, @Valid String hostid) { + if (!StringUtils.isBlank(hostid)) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("ivrList", extentionRes.findByExtypeAndOrgi("ivr", super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/index")); + } + + @RequestMapping(value = "/ivr/edit") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/edit")); + } + + @RequestMapping(value = "/ivr/update") + @Menu(type = "callcenter", subtype = "extention", admin = true) + public ModelAndView extentionupdate(HttpServletRequest request, @Valid Extention extention) { + if (!StringUtils.isBlank(extention.getId())) { + Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); + ext.setExtention(extention.getExtention()); + ext.setDescription(extention.getDescription()); + extentionRes.save(ext); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid=" + extention.getHostid())); + } + + + @RequestMapping(value = "/ivr/delete") + @Menu(type = "callcenter", subtype = "ivr", access = false, admin = true) + public ModelAndView extentiondelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + extentionRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/ivr.html?hostid=" + hostid)); + } + + @RequestMapping(value = "/ivr/design") + @Menu(type = "callcenter", subtype = "callcenterivr", admin = true) + public ModelAndView design(ModelMap map, HttpServletRequest request, @Valid String hostid, @Valid String id) { + if (!StringUtils.isBlank(hostid)) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.addAttribute("ivrMenuList", ivrMenuRes.findByExtentionidAndHostidAndOrgi(id, hostid, super.getOrgi(request))); + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/design")); + } + + @RequestMapping(value = "/ivr/menu/add") + @Menu(type = "callcenter", subtype = "callcenterivr", admin = true) + public ModelAndView ivrmenuadd(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/ivr/menuadd")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java index 9a96a605..8594140c 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterMediaController.java @@ -1,158 +1,166 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.MainUtils; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Media; -import com.chatopera.cc.persistence.repository.MediaRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.util.FileCopyUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.io.File; -import java.io.IOException; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterMediaController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private MediaRepository mediaRes ; - - @Value("${web.upload-path}") - private String path; - - @RequestMapping(value = "/media") - @Menu(type = "callcenter" , subtype = "callcentermedia" , access = false , admin = true) - public ModelAndView media(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("mediaList" , mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/index")); - } - - @RequestMapping(value = "/media/add") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediaadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/add")); - } - - @RequestMapping(value = "/media/save") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediasave(ModelMap map , HttpServletRequest request , @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { - Media media = new Media(); - media.setName(request.getParameter("name")); - media.setHostid(request.getParameter("hostid")); - if(!StringUtils.isBlank(media.getName())){ - int count = mediaRes.countByNameAndOrgi(media.getName(), super.getOrgi(request)) ; - if(count == 0){ - String fileName = "media/"+ MainUtils.getUUID()+mediafile.getOriginalFilename().substring(mediafile.getOriginalFilename().lastIndexOf(".")) ; - - media.setOrgi(super.getOrgi(request)); - media.setCreater(super.getUser(request).getId()); - media.setFilelength((int) mediafile.getSize()); - media.setContent(mediafile.getContentType()); - media.setFilename(fileName); - - if(mediafile!=null && mediafile.getOriginalFilename().lastIndexOf(".") > 0){ - File logoDir = new File(path , "media"); - if(!logoDir.exists()){ - logoDir.mkdirs() ; - } - FileCopyUtils.copy(mediafile.getBytes(), new File(path , fileName)); - } - - mediaRes.save(media) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+media.getHostid())); - } - - @RequestMapping(value = "/media/edit") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediaedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("media" , mediaRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/edit")); - } - - @RequestMapping(value = "/media/update") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { - Media media = new Media(); - media.setName(request.getParameter("name")); - media.setHostid(request.getParameter("hostid")); - media.setId(request.getParameter("id")); - if(!StringUtils.isBlank(media.getId())){ - Media oldMedia = mediaRes.findByIdAndOrgi(media.getId(), super.getOrgi(request)) ; - if(oldMedia!=null){ - if(mediafile!=null && mediafile.getSize() > 0){ - File wavFile = new File(path , oldMedia.getFilename()); - if(!wavFile.exists()){ - wavFile.deleteOnExit(); - } - - String fileName = "media/"+ MainUtils.getUUID()+mediafile.getOriginalFilename().substring(mediafile.getOriginalFilename().lastIndexOf(".")) ; - oldMedia.setFilename(fileName); - - if(mediafile!=null && mediafile.getOriginalFilename().lastIndexOf(".") > 0){ - File mediaDir = new File(path , "media"); - if(!mediaDir.exists()){ - mediaDir.mkdirs() ; - } - FileCopyUtils.copy(mediafile.getBytes(), new File(path , fileName)); - } - } - oldMedia.setName(media.getName()); - mediaRes.save(oldMedia); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+media.getHostid())); - } - - @RequestMapping(value = "/media/delete") - @Menu(type = "callcenter" , subtype = "media" , access = false , admin = true) - public ModelAndView mediadelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - mediaRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid="+hostid)); - } - @RequestMapping(value = "/play") - @Menu(type = "callcenter" , subtype = "play" , access = false) - public ModelAndView play(ModelMap map , HttpServletRequest request ,@Valid final String id ,@Valid final String hostid) { - map.addAttribute("media", mediaRes.findByIdAndOrgi(id, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/media/play")); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.basic.MainUtils; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Media; +import com.chatopera.cc.persistence.repository.MediaRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.io.File; +import java.io.IOException; +import java.util.Objects; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterMediaController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final MediaRepository mediaRes; + + @Value("${web.upload-path}") + private String path; + + @RequestMapping(value = "/media") + @Menu(type = "callcenter", subtype = "callcentermedia", access = false, admin = true) + public ModelAndView media(ModelMap map, HttpServletRequest request, @Valid String hostid) { + if (!StringUtils.isBlank(hostid)) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("mediaList", mediaRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/media/index")); + } + + @RequestMapping(value = "/media/add") + @Menu(type = "callcenter", subtype = "media", access = false, admin = true) + public ModelAndView mediaadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/media/add")); + } + + @RequestMapping(value = "/media/save") + @Menu(type = "callcenter", subtype = "media", access = false, admin = true) + public ModelAndView mediasave(HttpServletRequest request, @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { + Media media = new Media(); + media.setName(request.getParameter("name")); + media.setHostid(request.getParameter("hostid")); + if (!StringUtils.isBlank(media.getName())) { + int count = mediaRes.countByNameAndOrgi(media.getName(), super.getOrgi(request)); + if (count == 0) { + String fileName = "media/" + MainUtils.getUUID() + Objects.requireNonNull(mediafile.getOriginalFilename()) + .substring(mediafile.getOriginalFilename().lastIndexOf(".")); + + media.setOrgi(super.getOrgi(request)); + media.setCreater(super.getUser(request).getId()); + media.setFilelength((int) mediafile.getSize()); + media.setContent(mediafile.getContentType()); + media.setFilename(fileName); + + if (mediafile.getOriginalFilename().lastIndexOf(".") > 0) { + File logoDir = new File(path, "media"); + if (!logoDir.exists()) { + //noinspection ResultOfMethodCallIgnored + logoDir.mkdirs(); + } + FileCopyUtils.copy(mediafile.getBytes(), new File(path, fileName)); + } + + mediaRes.save(media); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid=" + media.getHostid())); + } + + @RequestMapping(value = "/media/edit") + @Menu(type = "callcenter", subtype = "media", access = false, admin = true) + public ModelAndView mediaedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("media", mediaRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/media/edit")); + } + + @RequestMapping(value = "/media/update") + @Menu(type = "callcenter", subtype = "media", access = false, admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @RequestParam(value = "mediafile", required = false) MultipartFile mediafile) throws IOException { + Media media = new Media(); + media.setName(request.getParameter("name")); + media.setHostid(request.getParameter("hostid")); + media.setId(request.getParameter("id")); + if (!StringUtils.isBlank(media.getId())) { + Media oldMedia = mediaRes.findByIdAndOrgi(media.getId(), super.getOrgi(request)); + if (oldMedia != null) { + if (mediafile != null && mediafile.getSize() > 0) { + File wavFile = new File(path, oldMedia.getFilename()); + if (!wavFile.exists()) { + wavFile.deleteOnExit(); + } + + String fileName = "media/" + MainUtils.getUUID() + Objects.requireNonNull(mediafile.getOriginalFilename()) + .substring(mediafile.getOriginalFilename().lastIndexOf(".")); + oldMedia.setFilename(fileName); + + if (mediafile.getOriginalFilename().lastIndexOf(".") > 0) { + File mediaDir = new File(path, "media"); + if (!mediaDir.exists()) { + //noinspection ResultOfMethodCallIgnored + mediaDir.mkdirs(); + } + FileCopyUtils.copy(mediafile.getBytes(), new File(path, fileName)); + } + } + oldMedia.setName(media.getName()); + mediaRes.save(oldMedia); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid=" + media.getHostid())); + } + + @RequestMapping(value = "/media/delete") + @Menu(type = "callcenter", subtype = "media", access = false, admin = true) + public ModelAndView mediadelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + mediaRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/media.html?hostid=" + hostid)); + } + + @RequestMapping(value = "/play") + @Menu(type = "callcenter", subtype = "play", access = false) + public ModelAndView play(ModelMap map, HttpServletRequest request, @Valid final String id) { + map.addAttribute("media", mediaRes.findByIdAndOrgi(id, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/media/play")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java index 7d880c49..3d38c5c5 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterResourceController.java @@ -1,133 +1,135 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.persistence.interfaces.CallCenterInterface; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.ServiceAiRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterResourceController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private ServiceAiRepository serviceAiRes; - - @RequestMapping(value = "/resource") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - - map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); - - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createAdminTempletResponse("/admin/callcenter/resource/index")); - } - - @RequestMapping(value = "/resource/config") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView config(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/resource/config")); - } - - @RequestMapping(value = "/resource/save") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView save(ModelMap map, HttpServletRequest request, @Valid PbxHost pbxHost) throws Exception { - PbxHost tempPbxHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); - if (tempPbxHost != null) { - pbxHost.setCreater(tempPbxHost.getCreater()); - pbxHost.setCreatetime(tempPbxHost.getCreatetime()); - if (StringUtils.isBlank(pbxHost.getPassword())) { - pbxHost.setPassword(tempPbxHost.getPassword()); - } - pbxHost.setOrgi(super.getOrgi(request)); - pbxHostRes.save(pbxHost); - - if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { - CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( - "callcenter"); - callCenterImpl.init(pbxHost); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/admin/callcenter/resource.html?hostid=" + pbxHost.getId())); - } - - @RequestMapping(value = "/resource/pbxhost") - @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) - public ModelAndView resourcepbx(ModelMap map, HttpServletRequest request, @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); - map.addAttribute("pbxHostList", pbxHostList); - PbxHost pbxHost = null; - if (pbxHostList.size() > 0) { - map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("extentionList", - extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); - } - return request(super.createAdminTempletResponse("/admin/callcenter/resource/pbxhost")); - } - - private PbxHost getPbxHost(List pbxHostList, String hostid) { - PbxHost pbxHost = pbxHostList.get(0); - if (!StringUtils.isBlank(hostid)) { - for (PbxHost pbx : pbxHostList) { - if (pbx.getId().equals(hostid)) { - pbxHost = pbx; - break; - } - } - } - return pbxHost; - } - -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.basic.Constants; +import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.persistence.interfaces.CallCenterInterface; +import com.chatopera.cc.persistence.repository.ExtentionRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.persistence.repository.ServiceAiRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterResourceController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final ExtentionRepository extentionRes; + + @NonNull + private final ServiceAiRepository serviceAiRes; + + @RequestMapping(value = "/resource") + @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) + public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + + map.put("serviceAiList", serviceAiRes.findByOrgi(super.getOrgi(request))); + + PbxHost pbxHost; + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); + map.addAttribute("extentionList", + extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + return request(super.createAdminTempletResponse("/admin/callcenter/resource/index")); + } + + @RequestMapping(value = "/resource/config") + @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) + public ModelAndView config(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + PbxHost pbxHost; + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); + map.addAttribute("extentionList", + extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/resource/config")); + } + + @RequestMapping(value = "/resource/save") + @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) + public ModelAndView save(HttpServletRequest request, @Valid PbxHost pbxHost) throws Exception { + PbxHost tempPbxHost = pbxHostRes.findByIdAndOrgi(pbxHost.getId(), super.getOrgi(request)); + if (tempPbxHost != null) { + pbxHost.setCreater(tempPbxHost.getCreater()); + pbxHost.setCreatetime(tempPbxHost.getCreatetime()); + if (StringUtils.isBlank(pbxHost.getPassword())) { + pbxHost.setPassword(tempPbxHost.getPassword()); + } + pbxHost.setOrgi(super.getOrgi(request)); + pbxHostRes.save(pbxHost); + + if (MainContext.hasModule(Constants.CSKEFU_MODULE_CALLCENTER)) { + CallCenterInterface callCenterImpl = (CallCenterInterface) MainContext.getContext().getBean( + "callcenter"); + callCenterImpl.init(pbxHost); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/admin/callcenter/resource.html?hostid=" + pbxHost.getId())); + } + + @RequestMapping(value = "/resource/pbxhost") + @Menu(type = "callcenter", subtype = "callcenter", access = false, admin = true) + public ModelAndView resourcepbx(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + PbxHost pbxHost; + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); + map.addAttribute("extentionList", + extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + return request(super.createAdminTempletResponse("/admin/callcenter/resource/pbxhost")); + } + + private PbxHost getPbxHost(List pbxHostList, String hostid) { + PbxHost pbxHost = pbxHostList.get(0); + if (!StringUtils.isBlank(hostid)) { + for (PbxHost pbx : pbxHostList) { + if (pbx.getId().equals(hostid)) { + pbxHost = pbx; + break; + } + } + } + return pbxHost; + } + +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java index 7d75d8ef..03186444 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterRouterController.java @@ -1,135 +1,136 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.RouterRules; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.RouterRulesRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterRouterController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - - @Autowired - private RouterRulesRepository routerRulesRes ; - - - @RequestMapping(value = "/router") - @Menu(type = "callcenter" , subtype = "callcenterresource" , access = false , admin = true) - public ModelAndView skill(ModelMap map , HttpServletRequest request , @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)) ; - map.addAttribute("pbxHostList" , pbxHostList); - if(pbxHostList.size() > 0){ - map.addAttribute("pbxHost" , pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("routerRulesList" , routerRulesRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/index")); - } - - @RequestMapping(value = "/router/add") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/add")); - } - - @RequestMapping(value = "/router/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionsave(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getName())){ - int count = routerRulesRes.countByNameAndOrgi(router.getName(), super.getOrgi(request)) ; - if(count == 0){ - router.setOrgi(super.getOrgi(request)); - router.setCreater(super.getUser(request).getId()); - routerRulesRes.save(router) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routeredit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("routerRules" , routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/edit")); - } - - @RequestMapping(value = "/router/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getId())){ - RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)) ; - if(oldRouter!=null){ - oldRouter.setName(router.getName()); - oldRouter.setField(router.getField()); - oldRouter.setRegex(router.getRegex()); - oldRouter.setRouterinx(router.getRouterinx()); - oldRouter.setFalsebreak(router.isFalsebreak()); - routerRulesRes.save(oldRouter); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/code") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routercode(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("routerRules" , routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/code")); - } - - @RequestMapping(value = "/router/code/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView routercodeupdate(ModelMap map , HttpServletRequest request , @Valid RouterRules router) { - if(!StringUtils.isBlank(router.getId())){ - RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)) ; - if(!StringUtils.isBlank(router.getRoutercontent())){ - oldRouter.setRoutercontent(router.getRoutercontent()); - routerRulesRes.save(oldRouter); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+router.getHostid())); - } - - @RequestMapping(value = "/router/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - routerRulesRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid="+hostid)); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.model.RouterRules; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.persistence.repository.RouterRulesRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterRouterController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final RouterRulesRepository routerRulesRes; + + + @RequestMapping(value = "/router") + @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) + public ModelAndView skill(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("routerRulesList", routerRulesRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/index")); + } + + @RequestMapping(value = "/router/add") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/add")); + } + + @RequestMapping(value = "/router/save") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionsave(HttpServletRequest request, @Valid RouterRules router) { + if (!StringUtils.isBlank(router.getName())) { + int count = routerRulesRes.countByNameAndOrgi(router.getName(), super.getOrgi(request)); + if (count == 0) { + router.setOrgi(super.getOrgi(request)); + router.setCreater(super.getUser(request).getId()); + routerRulesRes.save(router); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid=" + router.getHostid())); + } + + @RequestMapping(value = "/router/edit") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView routeredit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("routerRules", routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/edit")); + } + + @RequestMapping(value = "/router/update") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @Valid RouterRules router) { + if (!StringUtils.isBlank(router.getId())) { + RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)); + if (oldRouter != null) { + oldRouter.setName(router.getName()); + oldRouter.setField(router.getField()); + oldRouter.setRegex(router.getRegex()); + oldRouter.setRouterinx(router.getRouterinx()); + oldRouter.setFalsebreak(router.isFalsebreak()); + routerRulesRes.save(oldRouter); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid=" + router.getHostid())); + } + + @RequestMapping(value = "/router/code") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView routercode(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("routerRules", routerRulesRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/peer/code")); + } + + @RequestMapping(value = "/router/code/update") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView routercodeupdate(HttpServletRequest request, @Valid RouterRules router) { + if (!StringUtils.isBlank(router.getId())) { + RouterRules oldRouter = routerRulesRes.findByIdAndOrgi(router.getId(), super.getOrgi(request)); + if (!StringUtils.isBlank(router.getRoutercontent())) { + oldRouter.setRoutercontent(router.getRoutercontent()); + routerRulesRes.save(oldRouter); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid=" + router.getHostid())); + } + + @RequestMapping(value = "/router/delete") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentiondelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + routerRulesRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/peer.html?hostid=" + hostid)); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java index 4961f1aa..ff805227 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSipTrunkController.java @@ -1,152 +1,154 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.SipTrunk; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.SipTrunkRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterSipTrunkController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes; - - @Autowired - private SipTrunkRepository sipTrunkRes; - - @Autowired - private Cache cache; - - @RequestMapping(value = "/siptrunk") - @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) - public ModelAndView skill(ModelMap map, HttpServletRequest request, @Valid String hostid) { - if (!StringUtils.isBlank(hostid)) { - map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/index")); - } - - @RequestMapping(value = "/siptrunk/add") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/add")); - } - - @RequestMapping(value = "/siptrunk/save") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentionsave(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getName())) { - int count = sipTrunkRes.countByNameAndOrgi(siptrunk.getName(), super.getOrgi(request)); - if (count == 0) { - siptrunk.setOrgi(super.getOrgi(request)); - siptrunk.setCreater(super.getUser(request).getId()); - sipTrunkRes.save(siptrunk); - - cache.putSystemByIdAndOrgi(siptrunk.getId(), siptrunk.getOrgi(), siptrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/edit") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/edit")); - } - - @RequestMapping(value = "/siptrunk/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView pbxhostupdate(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getId())) { - SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); - if (oldSipTrunk != null) { - oldSipTrunk.setName(siptrunk.getName()); - oldSipTrunk.setSipserver(siptrunk.getSipserver()); - oldSipTrunk.setPort(siptrunk.getPort()); - oldSipTrunk.setProtocol(siptrunk.getProtocol()); - oldSipTrunk.setRegister(siptrunk.isRegister()); - oldSipTrunk.setDefaultsip(siptrunk.isDefaultsip()); - oldSipTrunk.setTitle(siptrunk.getTitle()); - - oldSipTrunk.setEnablecallagent(siptrunk.isEnablecallagent()); - - oldSipTrunk.setOutnumber(siptrunk.getOutnumber()); - oldSipTrunk.setBusyext(siptrunk.getBusyext()); - oldSipTrunk.setNotready(siptrunk.getNotready()); - - oldSipTrunk.setNoname(siptrunk.getNoname()); - - oldSipTrunk.setProvince(siptrunk.getProvince()); - oldSipTrunk.setCity(siptrunk.getCity()); - oldSipTrunk.setPrefix(siptrunk.getPrefix()); - - sipTrunkRes.save(oldSipTrunk); - cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/code") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkcode(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/code")); - } - - @RequestMapping(value = "/siptrunk/code/update") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView siptrunkcodeupdate(ModelMap map, HttpServletRequest request, @Valid SipTrunk siptrunk) { - if (!StringUtils.isBlank(siptrunk.getId())) { - SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); - if (!StringUtils.isBlank(siptrunk.getSipcontent())) { - oldSipTrunk.setSipcontent(siptrunk.getSipcontent()); - sipTrunkRes.save(oldSipTrunk); - cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); - } - - @RequestMapping(value = "/siptrunk/delete") - @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) - public ModelAndView extentiondelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { - if (!StringUtils.isBlank(id)) { - sipTrunkRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + hostid)); - } -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.cache.Cache; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.SipTrunk; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.persistence.repository.SipTrunkRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterSipTrunkController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final SipTrunkRepository sipTrunkRes; + + @NonNull + private final Cache cache; + + @RequestMapping(value = "/siptrunk") + @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) + public ModelAndView skill(ModelMap map, HttpServletRequest request, @Valid String hostid) { + if (!StringUtils.isBlank(hostid)) { + map.addAttribute("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("sipTrunkListList", sipTrunkRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/index")); + } + + @RequestMapping(value = "/siptrunk/add") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/add")); + } + + @RequestMapping(value = "/siptrunk/save") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionsave(HttpServletRequest request, @Valid SipTrunk siptrunk) { + if (!StringUtils.isBlank(siptrunk.getName())) { + int count = sipTrunkRes.countByNameAndOrgi(siptrunk.getName(), super.getOrgi(request)); + if (count == 0) { + siptrunk.setOrgi(super.getOrgi(request)); + siptrunk.setCreater(super.getUser(request).getId()); + sipTrunkRes.save(siptrunk); + + cache.putSystemByIdAndOrgi(siptrunk.getId(), siptrunk.getOrgi(), siptrunk); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); + } + + @RequestMapping(value = "/siptrunk/edit") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView siptrunkedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/edit")); + } + + @RequestMapping(value = "/siptrunk/update") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @Valid SipTrunk siptrunk) { + if (!StringUtils.isBlank(siptrunk.getId())) { + SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); + if (oldSipTrunk != null) { + oldSipTrunk.setName(siptrunk.getName()); + oldSipTrunk.setSipserver(siptrunk.getSipserver()); + oldSipTrunk.setPort(siptrunk.getPort()); + oldSipTrunk.setProtocol(siptrunk.getProtocol()); + oldSipTrunk.setRegister(siptrunk.isRegister()); + oldSipTrunk.setDefaultsip(siptrunk.isDefaultsip()); + oldSipTrunk.setTitle(siptrunk.getTitle()); + + oldSipTrunk.setEnablecallagent(siptrunk.isEnablecallagent()); + + oldSipTrunk.setOutnumber(siptrunk.getOutnumber()); + oldSipTrunk.setBusyext(siptrunk.getBusyext()); + oldSipTrunk.setNotready(siptrunk.getNotready()); + + oldSipTrunk.setNoname(siptrunk.getNoname()); + + oldSipTrunk.setProvince(siptrunk.getProvince()); + oldSipTrunk.setCity(siptrunk.getCity()); + oldSipTrunk.setPrefix(siptrunk.getPrefix()); + + sipTrunkRes.save(oldSipTrunk); + cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); + } + + @RequestMapping(value = "/siptrunk/code") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView siptrunkcode(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("siptrunk", sipTrunkRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/siptrunk/code")); + } + + @RequestMapping(value = "/siptrunk/code/update") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView siptrunkcodeupdate(HttpServletRequest request, @Valid SipTrunk siptrunk) { + if (!StringUtils.isBlank(siptrunk.getId())) { + SipTrunk oldSipTrunk = sipTrunkRes.findByIdAndOrgi(siptrunk.getId(), super.getOrgi(request)); + if (!StringUtils.isBlank(siptrunk.getSipcontent())) { + oldSipTrunk.setSipcontent(siptrunk.getSipcontent()); + sipTrunkRes.save(oldSipTrunk); + cache.putSystemByIdAndOrgi(oldSipTrunk.getId(), oldSipTrunk.getOrgi(), oldSipTrunk); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + siptrunk.getHostid())); + } + + @RequestMapping(value = "/siptrunk/delete") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentiondelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + sipTrunkRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/siptrunk.html?hostid=" + hostid)); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java index f83ce7e4..0e45bfc5 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/callcenter/CallCenterSkillController.java @@ -1,186 +1,189 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.admin.callcenter; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CallCenterSkill; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.SkillExtention; -import com.chatopera.cc.persistence.repository.CallCenterSkillRepository; -import com.chatopera.cc.persistence.repository.ExtentionRepository; -import com.chatopera.cc.persistence.repository.PbxHostRepository; -import com.chatopera.cc.persistence.repository.SkillExtentionRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.Date; -import java.util.List; - -@Controller -@RequestMapping("/admin/callcenter") -public class CallCenterSkillController extends Handler { - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private CallCenterSkillRepository skillRes ; - - @Autowired - private SkillExtentionRepository skillExtentionRes; - - @RequestMapping(value = "/skill") - @Menu(type = "callcenter" , subtype = "callcenterresource" , access = false , admin = true) - public ModelAndView skill(ModelMap map , HttpServletRequest request , @Valid String hostid) { - List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)) ; - map.addAttribute("pbxHostList" , pbxHostList); - PbxHost pbxHost = null ; - if(pbxHostList.size() > 0){ - map.addAttribute("pbxHost" , pbxHost = getPbxHost(pbxHostList, hostid)); - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("skillExtentionList" , skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/index")); - } - - private PbxHost getPbxHost(List pbxHostList ,String hostid){ - PbxHost pbxHost = pbxHostList.get(0) ; - if(!StringUtils.isBlank(hostid)){ - for(PbxHost pbx : pbxHostList){ - if(pbx.getId().equals(hostid)){ - pbxHost = pbx; break ; - } - } - } - return pbxHost ; - } - - @RequestMapping(value = "/skill/add") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionadd(ModelMap map , HttpServletRequest request , @Valid String hostid) { - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/add")); - } - - @RequestMapping(value = "/skill/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionsave(ModelMap map , HttpServletRequest request , @Valid CallCenterSkill skill) { - if(!StringUtils.isBlank(skill.getSkill())){ - int count = skillRes.countBySkillAndOrgi(skill.getSkill(), super.getOrgi(request)) ; - if(count == 0){ - skill.setOrgi(super.getOrgi(request)); - skill.setCreater(super.getUser(request).getId()); - skillRes.save(skill) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+skill.getHostid())); - } - - @RequestMapping(value = "/skill/edit") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentionedit(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - map.addAttribute("extention" , extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/edit")); - } - - @RequestMapping(value = "/skill/update") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView pbxhostupdate(ModelMap map , HttpServletRequest request , @Valid Extention extention) { - if(!StringUtils.isBlank(extention.getId())){ - Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)) ; - if(ext!=null && !StringUtils.isBlank(ext.getExtention()) && ext.getExtention().matches("[\\d]{3,8}")){ - ext.setExtention(extention.getExtention()); - if(!StringUtils.isBlank(extention.getPassword())){ - ext.setPassword(extention.getPassword()); - } - ext.setUpdatetime(new Date()); - extentionRes.save(ext) ; - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+extention.getHostid())); - } - - @RequestMapping(value = "/skill/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView extentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - extentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - - @RequestMapping(value = "/skill/imp") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillimp(ModelMap map , HttpServletRequest request , @Valid String hostid) { - if(!StringUtils.isBlank(hostid)){ - map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))) ; - map.put("extentionList", extentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))) ; - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(hostid , super.getOrgi(request))); - } - return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/imp")); - } - - @RequestMapping(value = "/skill/extention/delete") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillextentiondelete(ModelMap map , HttpServletRequest request , @Valid String id , @Valid String hostid) { - if(!StringUtils.isBlank(id)){ - skillExtentionRes.delete(id); - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - - @RequestMapping(value = "/skill/extention/save") - @Menu(type = "callcenter" , subtype = "extention" , access = false , admin = true) - public ModelAndView skillextentionsave(ModelMap map , HttpServletRequest request , @Valid SkillExtention skillExtention, @Valid String hostid , @Valid String[] exts) { - if(exts!=null && exts.length > 0){ - List skillExtentionList = skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request)) ; - for(String ext :exts){ - SkillExtention skillExt = new SkillExtention() ; - skillExt.setOrgi(super.getOrgi(request)); - skillExt.setCreater(super.getUser(request).getId()); - skillExt.setCreatetime(new Date()); - skillExt.setExtention(ext); - skillExt.setHostid(hostid); - skillExt.setSkillid(skillExtention.getSkillid()); - skillExt.setUpdatetime(new Date()); - boolean ingroup = false; - for(SkillExtention temp : skillExtentionList){ - if(temp.getSkillid().equals(skillExt.getSkillid()) && temp.getExtention().equals(skillExt.getExtention())){ - ingroup = true ; - } - } - if(ingroup == false){ - skillExtentionRes.save(skillExt) ; - } - } - } - return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid="+hostid)); - } - -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.admin.callcenter; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.CallCenterSkill; +import com.chatopera.cc.model.Extention; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.model.SkillExtention; +import com.chatopera.cc.persistence.repository.CallCenterSkillRepository; +import com.chatopera.cc.persistence.repository.ExtentionRepository; +import com.chatopera.cc.persistence.repository.PbxHostRepository; +import com.chatopera.cc.persistence.repository.SkillExtentionRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Date; +import java.util.List; + +@Controller +@RequestMapping("/admin/callcenter") +@RequiredArgsConstructor +public class CallCenterSkillController extends Handler { + + @org.springframework.lang.NonNull + private final PbxHostRepository pbxHostRes; + + @org.springframework.lang.NonNull + private final ExtentionRepository extentionRes; + + @org.springframework.lang.NonNull + private final CallCenterSkillRepository skillRes; + + @org.springframework.lang.NonNull + private final SkillExtentionRepository skillExtentionRes; + + @RequestMapping(value = "/skill") + @Menu(type = "callcenter", subtype = "callcenterresource", access = false, admin = true) + public ModelAndView skill(ModelMap map, HttpServletRequest request, @Valid String hostid) { + List pbxHostList = pbxHostRes.findByOrgi(super.getOrgi(request)); + map.addAttribute("pbxHostList", pbxHostList); + PbxHost pbxHost; + if (pbxHostList.size() > 0) { + map.addAttribute("pbxHost", pbxHost = getPbxHost(pbxHostList, hostid)); + map.addAttribute("skillGroups", skillRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("skillExtentionList", skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/index")); + } + + private PbxHost getPbxHost(List pbxHostList, String hostid) { + PbxHost pbxHost = pbxHostList.get(0); + if (!StringUtils.isBlank(hostid)) { + for (PbxHost pbx : pbxHostList) { + if (pbx.getId().equals(hostid)) { + pbxHost = pbx; + break; + } + } + } + return pbxHost; + } + + @RequestMapping(value = "/skill/add") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionadd(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/add")); + } + + @RequestMapping(value = "/skill/save") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionsave(HttpServletRequest request, @Valid CallCenterSkill skill) { + if (!StringUtils.isBlank(skill.getSkill())) { + int count = skillRes.countBySkillAndOrgi(skill.getSkill(), super.getOrgi(request)); + if (count == 0) { + skill.setOrgi(super.getOrgi(request)); + skill.setCreater(super.getUser(request).getId()); + skillRes.save(skill); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid=" + skill.getHostid())); + } + + @RequestMapping(value = "/skill/edit") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentionedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String hostid) { + map.addAttribute("extention", extentionRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/edit")); + } + + @RequestMapping(value = "/skill/update") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView pbxhostupdate(HttpServletRequest request, @Valid Extention extention) { + if (!StringUtils.isBlank(extention.getId())) { + Extention ext = extentionRes.findByIdAndOrgi(extention.getId(), super.getOrgi(request)); + if (ext != null && !StringUtils.isBlank(ext.getExtention()) && ext.getExtention().matches("[\\d]{3,8}")) { + ext.setExtention(extention.getExtention()); + if (!StringUtils.isBlank(extention.getPassword())) { + ext.setPassword(extention.getPassword()); + } + ext.setUpdatetime(new Date()); + extentionRes.save(ext); + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid=" + extention.getHostid())); + } + + @RequestMapping(value = "/skill/delete") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView extentiondelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + extentionRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid=" + hostid)); + } + + @RequestMapping(value = "/skill/imp") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView skillimp(ModelMap map, HttpServletRequest request, @Valid String hostid) { + if (!StringUtils.isBlank(hostid)) { + map.put("pbxHost", pbxHostRes.findByIdAndOrgi(hostid, super.getOrgi(request))); + map.put("extentionList", extentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + map.addAttribute("skillGroups", skillRes.findByHostidAndOrgi(hostid, super.getOrgi(request))); + } + return request(super.createRequestPageTempletResponse("/admin/callcenter/skill/imp")); + } + + @RequestMapping(value = "/skill/extention/delete") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView skillextentiondelete(@Valid String id, @Valid String hostid) { + if (!StringUtils.isBlank(id)) { + skillExtentionRes.deleteById(id); + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid=" + hostid)); + } + + @RequestMapping(value = "/skill/extention/save") + @Menu(type = "callcenter", subtype = "extention", access = false, admin = true) + public ModelAndView skillextentionsave(HttpServletRequest request, @Valid SkillExtention skillExtention, @Valid String hostid, @Valid String[] exts) { + if (exts != null && exts.length > 0) { + List skillExtentionList = skillExtentionRes.findByHostidAndOrgi(hostid, super.getOrgi(request)); + for (String ext : exts) { + SkillExtention skillExt = new SkillExtention(); + skillExt.setOrgi(super.getOrgi(request)); + skillExt.setCreater(super.getUser(request).getId()); + skillExt.setCreatetime(new Date()); + skillExt.setExtention(ext); + skillExt.setHostid(hostid); + skillExt.setSkillid(skillExtention.getSkillid()); + skillExt.setUpdatetime(new Date()); + boolean ingroup = false; + for (SkillExtention temp : skillExtentionList) { + if (temp.getSkillid().equals(skillExt.getSkillid()) && temp.getExtention().equals(skillExt.getExtention())) { + ingroup = true; + break; + } + } + if (!ingroup) { + skillExtentionRes.save(skillExt); + } + } + } + return request(super.createRequestPageTempletResponse("redirect:/admin/callcenter/skill.html?hostid=" + hostid)); + } + +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/ExtentionController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/ExtentionController.java index b3549bac..ecbc0611 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/ExtentionController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/ExtentionController.java @@ -1,189 +1,188 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.controller.apps; - -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.basic.MainUtils; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.Extention; -import com.chatopera.cc.model.PbxHost; -import com.chatopera.cc.model.SystemConfig; -import com.chatopera.cc.model.Template; -import com.chatopera.cc.persistence.repository.*; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/apps/callcenter") -public class ExtentionController extends Handler{ - - @Autowired - private PbxHostRepository pbxHostRes ; - - @Autowired - private ExtentionRepository extentionRes; - - @Autowired - private AclRepository aclRes; - - @Autowired - private RouterRulesRepository routerRes; - - @Autowired - private SkillExtentionRepository skillExtentionRes ; - - @Autowired - private CallCenterSkillRepository skillRes ; - - @Autowired - private SipTrunkRepository sipTrunkRes ; - - @RequestMapping(value = "/extention") - @Menu(type = "callcenter" , subtype = "extention" , access = true) - public ModelAndView index(ModelMap map , HttpServletRequest request , @Valid String hostname , @Valid String key_value) { - ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/index")) ; - List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname) ; - PbxHost pbxHost = null ; - SystemConfig systemConfig = MainUtils.getSystemConfig() ; - if(pbxHostList!=null && pbxHostList.size() > 0){ - pbxHost = pbxHostList.get(0) ; - map.addAttribute("pbxHost" , pbxHost); - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("extentionList" , extentionRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - } - if(systemConfig!=null && systemConfig.isCallcenter()){ - if(!StringUtils.isBlank(systemConfig.getCc_extention())){ - Template template = MainUtils.getTemplate(systemConfig.getCc_extention()) ; - if(template!=null){ - map.addAttribute("template" , template); - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")) ; - } - } - } - return view ; - } - - @RequestMapping(value = "/configuration") - @Menu(type = "callcenter" , subtype = "configuration" , access = true) - public ModelAndView configuration(ModelMap map , HttpServletRequest request , @Valid String hostname , @Valid String key_value , @Valid String profile) { - - List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname) ; - PbxHost pbxHost = null ; - SystemConfig systemConfig = MainUtils.getSystemConfig() ; - if(pbxHostList!=null && pbxHostList.size() > 0){ - pbxHost = pbxHostList.get(0) ; - map.addAttribute("pbxHost" , pbxHost); - map.addAttribute("skillGroups" , skillRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("skillExtentionList" , skillExtentionRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("extentionList" , extentionRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("aclList" , aclRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - map.addAttribute("sipTrunkList" , sipTrunkRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - } - Template template = null ; - ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/notfound")); - if(key_value!=null && key_value.equals("callcenter.conf")){ - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/callcenter")); - if(systemConfig!=null && systemConfig.isCallcenter()){ - if(!StringUtils.isBlank(systemConfig.getCc_quene())){ - template = MainUtils.getTemplate(systemConfig.getCc_quene()) ; - } - } - }else if(key_value!=null && key_value.equals("acl.conf")){ - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/acl")); - if(systemConfig!=null && systemConfig.isCallcenter()){ - if(!StringUtils.isBlank(systemConfig.getCc_acl())){ - template = MainUtils.getTemplate(systemConfig.getCc_acl()) ; - } - } - }else if(key_value!=null && key_value.equals("ivr.conf")){ - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/ivr")); - if(systemConfig!=null && systemConfig.isCallcenter()){ - if(!StringUtils.isBlank(systemConfig.getCc_ivr())){ - template = MainUtils.getTemplate(systemConfig.getCc_ivr()) ; - } - } - } - if(template!=null){ - map.addAttribute("template" , template); - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")) ; - } - return view; - } - - @RequestMapping(value = "/dialplan") - @Menu(type = "callcenter" , subtype = "dialplan" , access = true) - public ModelAndView dialplan(ModelMap map , HttpServletRequest request , @Valid String hostname , @Valid String key_value) { - ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/dialplan/index")); - List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname) ; - PbxHost pbxHost = null ; - SystemConfig systemConfig = MainUtils.getSystemConfig() ; - Template template = null ; - if(pbxHostList!=null && pbxHostList.size() > 0){ - pbxHost = pbxHostList.get(0) ; - map.addAttribute("pbxHost" , pbxHost); - map.addAttribute("routerList" , routerRes.findByHostidAndOrgi(pbxHost.getId() , super.getOrgi(request))); - } - if(systemConfig!=null && systemConfig.isCallcenter()){ - if(!StringUtils.isBlank(systemConfig.getCc_siptrunk())){ - template = MainUtils.getTemplate(systemConfig.getCc_router()) ; - } - if(template!=null){ - map.addAttribute("template" , template); - view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")) ; - } - } - - return view; - } - - @RequestMapping(value = "/extention/detail") - @Menu(type = "callcenter" , subtype = "extention" , access = false) - public ModelAndView detail(ModelMap map , HttpServletRequest request , HttpServletResponse response ,@Valid String extno) { - List extentionList = extentionRes.findByExtentionAndOrgi(extno, super.getOrgi(request)) ; - if(extentionList!=null && extentionList.size() == 1){ - Extention extention = extentionList.get(0) ; - if(!StringUtils.isBlank(extention.getHostid())) { - PbxHost pbxHost = pbxHostRes.findById(extention.getHostid()) ; - if(pbxHost!=null) { - map.addAttribute("pbxhost" , pbxHost); - } - } - map.addAttribute("extention" , extention); - } - response.setContentType("Content-type: text/json; charset=utf-8"); - return request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/detail")); - } - - @RequestMapping(value = "/ivr") - @Menu(type = "callcenter" , subtype = "ivr" , access = false) - public ModelAndView ivr(ModelMap map , HttpServletRequest request , HttpServletResponse response ,@Valid String hostid) { - map.addAttribute("ivrList" , extentionRes.findByHostidAndExtypeAndOrgi(hostid, MainContext.ExtentionType.BUSINESS.toString() , super.getOrgi(request))); - return request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/ivr")); - } - -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.controller.apps; + +import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.basic.MainUtils; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.Extention; +import com.chatopera.cc.model.PbxHost; +import com.chatopera.cc.model.SystemConfig; +import com.chatopera.cc.model.Template; +import com.chatopera.cc.persistence.repository.*; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/apps/callcenter") +@RequiredArgsConstructor +public class ExtentionController extends Handler { + + @NonNull + private final PbxHostRepository pbxHostRes; + + @NonNull + private final ExtentionRepository extentionRes; + + @NonNull + private final AclRepository aclRes; + + @NonNull + private final RouterRulesRepository routerRes; + + @NonNull + private final SkillExtentionRepository skillExtentionRes; + + @NonNull + private final CallCenterSkillRepository skillRes; + + @NonNull + private final SipTrunkRepository sipTrunkRes; + + @RequestMapping(value = "/extention") + @Menu(type = "callcenter", subtype = "extention", access = true) + public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String hostname) { + ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/index")); + List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname); + PbxHost pbxHost; + SystemConfig systemConfig = MainUtils.getSystemConfig(); + if (pbxHostList != null && pbxHostList.size() > 0) { + pbxHost = pbxHostList.get(0); + map.addAttribute("pbxHost", pbxHost); + map.addAttribute("skillGroups", skillRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("extentionList", extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + if (systemConfig != null && systemConfig.isCallcenter()) { + if (!StringUtils.isBlank(systemConfig.getCc_extention())) { + Template template = MainUtils.getTemplate(systemConfig.getCc_extention()); + if (template != null) { + map.addAttribute("template", template); + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")); + } + } + } + return view; + } + + @RequestMapping(value = "/configuration") + @Menu(type = "callcenter", subtype = "configuration", access = true) + public ModelAndView configuration(ModelMap map, HttpServletRequest request, @Valid String hostname, @Valid String key_value) { + + List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname); + PbxHost pbxHost; + SystemConfig systemConfig = MainUtils.getSystemConfig(); + if (pbxHostList != null && pbxHostList.size() > 0) { + pbxHost = pbxHostList.get(0); + map.addAttribute("pbxHost", pbxHost); + map.addAttribute("skillGroups", skillRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("skillExtentionList", skillExtentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("extentionList", extentionRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("aclList", aclRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + map.addAttribute("sipTrunkList", sipTrunkRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + Template template = null; + ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/notfound")); + if (key_value != null && key_value.equals("callcenter.conf")) { + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/callcenter")); + if (systemConfig != null && systemConfig.isCallcenter()) { + if (!StringUtils.isBlank(systemConfig.getCc_quene())) { + template = MainUtils.getTemplate(systemConfig.getCc_quene()); + } + } + } else if (key_value != null && key_value.equals("acl.conf")) { + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/acl")); + if (systemConfig != null && systemConfig.isCallcenter()) { + if (!StringUtils.isBlank(systemConfig.getCc_acl())) { + template = MainUtils.getTemplate(systemConfig.getCc_acl()); + } + } + } else if (key_value != null && key_value.equals("ivr.conf")) { + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/configure/ivr")); + if (systemConfig != null && systemConfig.isCallcenter()) { + if (!StringUtils.isBlank(systemConfig.getCc_ivr())) { + template = MainUtils.getTemplate(systemConfig.getCc_ivr()); + } + } + } + if (template != null) { + map.addAttribute("template", template); + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")); + } + return view; + } + + @RequestMapping(value = "/dialplan") + @Menu(type = "callcenter", subtype = "dialplan", access = true) + public ModelAndView dialplan(ModelMap map, HttpServletRequest request, @Valid String hostname) { + ModelAndView view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/dialplan/index")); + List pbxHostList = pbxHostRes.findByHostnameOrIpaddr(hostname, hostname); + PbxHost pbxHost; + SystemConfig systemConfig = MainUtils.getSystemConfig(); + Template template = null; + if (pbxHostList != null && pbxHostList.size() > 0) { + pbxHost = pbxHostList.get(0); + map.addAttribute("pbxHost", pbxHost); + map.addAttribute("routerList", routerRes.findByHostidAndOrgi(pbxHost.getId(), super.getOrgi(request))); + } + if (systemConfig != null && systemConfig.isCallcenter()) { + if (!StringUtils.isBlank(systemConfig.getCc_siptrunk())) { + template = MainUtils.getTemplate(systemConfig.getCc_router()); + } + if (template != null) { + map.addAttribute("template", template); + view = request(super.createRequestPageTempletResponse("/apps/business/callcenter/template")); + } + } + + return view; + } + + @RequestMapping(value = "/extention/detail") + @Menu(type = "callcenter", subtype = "extention") + public ModelAndView detail(ModelMap map, HttpServletRequest request, HttpServletResponse response, @Valid String extno) { + List extentionList = extentionRes.findByExtentionAndOrgi(extno, super.getOrgi(request)); + if (extentionList != null && extentionList.size() == 1) { + Extention extention = extentionList.get(0); + if (!StringUtils.isBlank(extention.getHostid())) { + pbxHostRes.findById(extention.getHostid()).ifPresent(it -> map.addAttribute("pbxhost", it)); + } + map.addAttribute("extention", extention); + } + response.setContentType("Content-type: text/json; charset=utf-8"); + return request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/detail")); + } + + @RequestMapping(value = "/ivr") + @Menu(type = "callcenter", subtype = "ivr") + public ModelAndView ivr(ModelMap map, HttpServletRequest request, @Valid String hostid) { + map.addAttribute("ivrList", extentionRes.findByHostidAndExtypeAndOrgi(hostid, MainContext.ExtentionType.BUSINESS.toString(), super.getOrgi(request))); + return request(super.createRequestPageTempletResponse("/apps/business/callcenter/extention/ivr")); + } + +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/PbxHostRepository.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/PbxHostRepository.java index 758d6272..d4b96b8a 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/PbxHostRepository.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/PbxHostRepository.java @@ -1,33 +1,36 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * 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.PbxHost; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface PbxHostRepository extends JpaRepository { - - PbxHost findByIdAndOrgi(String id, String orgi); - PbxHost findById(String id); - List findByOrgi(String orgi); - List findByHostnameOrIpaddr(String hostname, String ip); - - int countByHostnameAndOrgi(String hostname, String orgi) ; - -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * 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.PbxHost; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface PbxHostRepository extends JpaRepository { + + PbxHost findByIdAndOrgi(String id, String orgi); + + // PbxHost findById(String id); + + List findByOrgi(String orgi); + + List findByHostnameOrIpaddr(String hostname, String ip); + + int countByHostnameAndOrgi(String hostname, String orgi); + +}