mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
Fix SysDicRepository related class
This commit is contained in:
parent
a3e5b1660e
commit
4f4616ccba
@ -31,8 +31,9 @@ import com.chatopera.cc.persistence.repository.UserRepository;
|
||||
import com.chatopera.cc.proxy.OnlineUserProxy;
|
||||
import com.chatopera.cc.socketio.client.NettyClients;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -45,28 +46,29 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class AdminController extends Handler {
|
||||
|
||||
@Autowired
|
||||
private ACDWorkMonitor acdWorkMonitor;
|
||||
@NonNull
|
||||
private final ACDWorkMonitor acdWorkMonitor;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRes;
|
||||
@NonNull
|
||||
private final UserRepository userRes;
|
||||
|
||||
@Autowired
|
||||
private OnlineUserRepository onlineUserRes;
|
||||
@NonNull
|
||||
private final OnlineUserRepository onlineUserRes;
|
||||
|
||||
@Autowired
|
||||
private UserEventRepository userEventRes;
|
||||
@NonNull
|
||||
private final UserEventRepository userEventRes;
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository sysDicRes;
|
||||
@NonNull
|
||||
private final SysDicRepository sysDicRes;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
@NonNull
|
||||
private final Cache cache;
|
||||
|
||||
@RequestMapping("/admin")
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request) {
|
||||
public ModelAndView index(HttpServletRequest request) {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/"));
|
||||
User user = super.getUser(request);
|
||||
view.addObject("agentStatusReport", acdWorkMonitor.getAgentReport(user.getOrgi()));
|
||||
@ -107,13 +109,13 @@ public class AdminController extends Handler {
|
||||
|
||||
private List<User> getAgent(HttpServletRequest request) {
|
||||
//获取当前产品or租户坐席数
|
||||
List<User> userList = new ArrayList<>();
|
||||
List<User> userList;
|
||||
if (super.isEnabletneant()) {
|
||||
userList = userRes.findByOrgidAndAgentAndDatastatus(super.getOrgid(request), true, false);
|
||||
} else {
|
||||
userList = userRes.findByOrgiAndAgentAndDatastatus(super.getOrgi(request), true, false);
|
||||
}
|
||||
return userList.isEmpty() ? new ArrayList<User>() : userList;
|
||||
return userList.isEmpty() ? new ArrayList<>() : userList;
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/content")
|
||||
@ -131,7 +133,7 @@ public class AdminController extends Handler {
|
||||
|
||||
@RequestMapping("/admin/auth/infoacq")
|
||||
@Menu(type = "admin", subtype = "infoacq", admin = true)
|
||||
public ModelAndView infoacq(ModelMap map, HttpServletRequest request) {
|
||||
public ModelAndView infoacq(HttpServletRequest request) {
|
||||
String inacq = (String) request.getSession().getAttribute(Constants.CSKEFU_SYSTEM_INFOACQ);
|
||||
if (StringUtils.isNotBlank(inacq)) {
|
||||
request.getSession().removeAttribute(Constants.CSKEFU_SYSTEM_INFOACQ);
|
||||
@ -143,7 +145,7 @@ public class AdminController extends Handler {
|
||||
|
||||
@RequestMapping("/admin/auth/event")
|
||||
@Menu(type = "admin", subtype = "authevent")
|
||||
public ModelAndView authevent(ModelMap map, HttpServletRequest request, @Valid String title, @Valid String url, @Valid String iconstr, @Valid String icontext) {
|
||||
public ModelAndView authevent(ModelMap map, @Valid String title, @Valid String url, @Valid String iconstr, @Valid String icontext) {
|
||||
map.addAttribute("title", title);
|
||||
map.addAttribute("url", url);
|
||||
if (StringUtils.isNotBlank(iconstr) && StringUtils.isNotBlank(icontext)) {
|
||||
@ -154,7 +156,7 @@ public class AdminController extends Handler {
|
||||
|
||||
@RequestMapping("/admin/auth/save")
|
||||
@Menu(type = "admin", subtype = "authsave")
|
||||
public ModelAndView authsave(ModelMap map, HttpServletRequest request, @Valid String title, @Valid SysDic dic) {
|
||||
public ModelAndView authsave(HttpServletRequest request, @Valid SysDic dic) {
|
||||
SysDic sysDic = sysDicRes.findByCode(Constants.CSKEFU_SYSTEM_AUTH_DIC);
|
||||
boolean newdic = false;
|
||||
if (sysDic != null && StringUtils.isNotBlank(dic.getName())) {
|
||||
|
@ -1,127 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainUtils;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.AreaType;
|
||||
import com.chatopera.cc.model.Dict;
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import com.chatopera.cc.persistence.repository.AreaTypeRepository;
|
||||
import com.chatopera.cc.persistence.repository.SysDicRepository;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
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.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @blog http://blog.didispace.com
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/admin/area")
|
||||
public class AreaController extends Handler{
|
||||
|
||||
@Autowired
|
||||
private AreaTypeRepository areaRepository;
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository sysDicRepository;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin" , subtype = "area")
|
||||
public ModelAndView index(ModelMap map , HttpServletRequest request) throws IOException {
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgi(request)));
|
||||
return request(super.createAdminTempletResponse("/admin/area/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin" , subtype = "area")
|
||||
public ModelAndView add(ModelMap map , HttpServletRequest request) {
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC) ;
|
||||
if(sysDic!=null){
|
||||
map.addAttribute("sysarea", sysDic) ;
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId())) ;
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC)) ;
|
||||
return request(super.createRequestPageTempletResponse("/admin/area/add"));
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
@Menu(type = "admin" , subtype = "area")
|
||||
public ModelAndView save(HttpServletRequest request ,@Valid AreaType area) {
|
||||
int areas = areaRepository.countByNameAndOrgi(area.getName(), super.getOrgi(request)) ;
|
||||
if(areas == 0){
|
||||
area.setOrgi(super.getOrgi(request));
|
||||
area.setCreatetime(new Date());
|
||||
area.setCreater(super.getUser(request).getId());
|
||||
areaRepository.save(area) ;
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin" , subtype = "area")
|
||||
public ModelAndView edit(ModelMap map ,HttpServletRequest request , @Valid String id) {
|
||||
map.addAttribute("area", areaRepository.findByIdAndOrgi(id, super.getOrgi(request))) ;
|
||||
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC) ;
|
||||
if(sysDic!=null){
|
||||
map.addAttribute("sysarea", sysDic) ;
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId())) ;
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC)) ;
|
||||
return request(super.createRequestPageTempletResponse("/admin/area/edit"));
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@Menu(type = "admin" , subtype = "area" , admin = true)
|
||||
public ModelAndView update(HttpServletRequest request ,@Valid AreaType area) {
|
||||
AreaType areaType = areaRepository.findByIdAndOrgi(area.getId(), super.getOrgi(request)) ;
|
||||
if(areaType != null){
|
||||
area.setCreatetime(areaType.getCreatetime());
|
||||
area.setOrgi(super.getOrgi(request));
|
||||
area.setCreater(areaType.getCreater());
|
||||
areaRepository.save(area) ;
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin" , subtype = "area")
|
||||
public ModelAndView delete(HttpServletRequest request ,@Valid AreaType area) {
|
||||
AreaType areaType = areaRepository.findByIdAndOrgi(area.getId(), super.getOrgi(request)) ;
|
||||
if(areaType!=null){
|
||||
areaRepository.delete(areaType);
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainUtils;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.AreaType;
|
||||
import com.chatopera.cc.model.Dict;
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import com.chatopera.cc.persistence.repository.AreaTypeRepository;
|
||||
import com.chatopera.cc.persistence.repository.SysDicRepository;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author <a href="http://blog.didispace.com">程序猿DD</a>
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/admin/area")
|
||||
@RequiredArgsConstructor
|
||||
public class AreaController extends Handler {
|
||||
|
||||
@NonNull
|
||||
private final AreaTypeRepository areaRepository;
|
||||
|
||||
@NonNull
|
||||
private final SysDicRepository sysDicRepository;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request) {
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgi(request)));
|
||||
return request(super.createAdminTempletResponse("/admin/area/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView add(ModelMap map) {
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC);
|
||||
if (sysDic != null) {
|
||||
map.addAttribute("sysarea", sysDic);
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId()));
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC));
|
||||
return request(super.createRequestPageTempletResponse("/admin/area/add"));
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView save(HttpServletRequest request, @Valid AreaType area) {
|
||||
int areas = areaRepository.countByNameAndOrgi(area.getName(), super.getOrgi(request));
|
||||
if (areas == 0) {
|
||||
area.setOrgi(super.getOrgi(request));
|
||||
area.setCreatetime(new Date());
|
||||
area.setCreater(super.getUser(request).getId());
|
||||
areaRepository.save(area);
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
map.addAttribute("area", areaRepository.findByIdAndOrgi(id, super.getOrgi(request)));
|
||||
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC);
|
||||
if (sysDic != null) {
|
||||
map.addAttribute("sysarea", sysDic);
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId()));
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC));
|
||||
return request(super.createRequestPageTempletResponse("/admin/area/edit"));
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@Menu(type = "admin", subtype = "area", admin = true)
|
||||
public ModelAndView update(HttpServletRequest request, @Valid AreaType area) {
|
||||
AreaType areaType = areaRepository.findByIdAndOrgi(area.getId(), super.getOrgi(request));
|
||||
if (areaType != null) {
|
||||
area.setCreatetime(areaType.getCreatetime());
|
||||
area.setOrgi(super.getOrgi(request));
|
||||
area.setCreater(areaType.getCreater());
|
||||
areaRepository.save(area);
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid AreaType area) {
|
||||
AreaType areaType = areaRepository.findByIdAndOrgi(area.getId(), super.getOrgi(request));
|
||||
if (areaType != null) {
|
||||
areaRepository.delete(areaType);
|
||||
MainUtils.initSystemArea();
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/area/index.html"));
|
||||
}
|
||||
}
|
||||
|
@ -1,377 +1,368 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainContext;
|
||||
import com.chatopera.cc.cache.Cache;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.*;
|
||||
import com.chatopera.cc.persistence.repository.*;
|
||||
import com.chatopera.cc.proxy.OnlineUserProxy;
|
||||
import com.chatopera.cc.proxy.OrganProxy;
|
||||
import com.chatopera.cc.proxy.UserProxy;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @blog http://blog.didispace.com
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/admin/organ")
|
||||
public class OrganController extends Handler {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(OrganController.class);
|
||||
|
||||
@Autowired
|
||||
private OrganRepository organRepository;
|
||||
|
||||
@Autowired
|
||||
private OrganUserRepository organUserRes;
|
||||
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository sysDicRepository;
|
||||
|
||||
@Autowired
|
||||
private AreaTypeRepository areaRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private OrganRoleRepository organRoleRes;
|
||||
|
||||
@Autowired
|
||||
private OrganProxy organProxy;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Autowired
|
||||
private UserProxy userProxy;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String organ, @Valid String msg) {
|
||||
List<Organ> organList = organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request), super.getOrgid(request));
|
||||
map.addAttribute("organList", organList);
|
||||
if (organList.size() > 0) {
|
||||
Organ organData = null;
|
||||
if (!StringUtils.isBlank(organ) && !"null".equals(organ)) {
|
||||
for (Organ data : organList) {
|
||||
if (data.getId().equals(organ)) {
|
||||
map.addAttribute("organData", data);
|
||||
organData = data;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
map.addAttribute("organData", organData = organList.get(0));
|
||||
}
|
||||
if (organData != null) {
|
||||
map.addAttribute(
|
||||
"userList", userProxy.findByOrganAndOrgiAndDatastatus(
|
||||
organData.getId(),
|
||||
super.getOrgiByTenantshare(request),
|
||||
false));
|
||||
}
|
||||
}
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
map.addAttribute(
|
||||
"roleList", roleRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
map.put("msg", msg);
|
||||
return request(super.createAdminTempletResponse("/admin/organ/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String parent, @Valid String area) {
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
if (!StringUtils.isBlank(parent)) {
|
||||
map.addAttribute("organ", organRepository.findByIdAndOrgi(parent, super.getOrgiByTenantshare(request)));
|
||||
}
|
||||
if (!StringUtils.isBlank(area)) {
|
||||
map.addAttribute("area", areaRepository.findByIdAndOrgi(area, super.getOrgiByTenantshare(request)));
|
||||
}
|
||||
|
||||
map.addAttribute(
|
||||
"organList", organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/add"));
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView save(HttpServletRequest request, @Valid Organ organ) {
|
||||
Organ tempOrgan = organRepository.findByNameAndOrgiAndOrgid(
|
||||
organ.getName(), super.getOrgiByTenantshare(request), super.getOrgid(request));
|
||||
String msg = "admin_organ_new_success";
|
||||
String firstId = null;
|
||||
if (tempOrgan != null) {
|
||||
msg = "admin_organ_update_name_not"; //分类名字重复
|
||||
} else {
|
||||
organ.setOrgi(super.getOrgiByTenantshare(request));
|
||||
|
||||
if (!StringUtils.isBlank(super.getUser(request).getOrgid())) {
|
||||
organ.setOrgid(super.getUser(request).getOrgid());
|
||||
} else {
|
||||
organ.setOrgid(MainContext.SYSTEM_ORGI);
|
||||
}
|
||||
firstId = organ.getId();
|
||||
|
||||
organRepository.save(organ);
|
||||
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + firstId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户到当前部门时选择坐席
|
||||
*
|
||||
* @param map
|
||||
* @param request
|
||||
* @param organ
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/seluser")
|
||||
@Menu(type = "admin", subtype = "seluser", admin = true)
|
||||
public ModelAndView seluser(ModelMap map, HttpServletRequest request, @Valid String organ) {
|
||||
map.addAttribute(
|
||||
"userList", userRepository.findByOrgiAndDatastatusAndOrgid(super.getOrgiByTenantshare(request), false,
|
||||
super.getOrgid(request)));
|
||||
Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request));
|
||||
map.addAttribute("userOrganList", userProxy
|
||||
.findByOrganAndOrgiAndDatastatus(organ, super.getOrgiByTenantshare(request), false));
|
||||
map.addAttribute("organ", organData);
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/seluser"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行添加用户到组织中
|
||||
*
|
||||
* @param request
|
||||
* @param users
|
||||
* @param organ
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/saveuser")
|
||||
@Menu(type = "admin", subtype = "saveuser", admin = true)
|
||||
public ModelAndView saveuser(
|
||||
HttpServletRequest request,
|
||||
final @Valid String[] users,
|
||||
final @Valid String organ
|
||||
) {
|
||||
logger.info("[saveuser] save users {} into organ {}", StringUtils.join(users, ","), organ);
|
||||
final User loginUser = super.getUser(request);
|
||||
|
||||
if (users != null && users.length > 0) {
|
||||
List<String> chosen = new ArrayList<String>(Arrays.asList(users));
|
||||
Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request));
|
||||
List<User> organUserList = userRepository.findAll(chosen);
|
||||
for (final User user : organUserList) {
|
||||
OrganUser ou = organUserRes.findByUseridAndOrgan(user.getId(), organ);
|
||||
|
||||
/**
|
||||
* 检查人员和技能组关系
|
||||
*/
|
||||
if (organData.isSkill()) {
|
||||
// 该组织机构是技能组
|
||||
if (!user.isAgent()) {
|
||||
// 该人员不是坐席
|
||||
if (ou != null) {
|
||||
organUserRes.delete(ou);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ou == null) {
|
||||
ou = new OrganUser();
|
||||
}
|
||||
|
||||
ou.setCreator(loginUser.getId());
|
||||
ou.setUserid(user.getId());
|
||||
ou.setOrgan(organ);
|
||||
|
||||
organUserRes.save(ou);
|
||||
|
||||
if (user.isAgent()) {
|
||||
/**
|
||||
* 以下更新技能组状态
|
||||
*/
|
||||
AgentStatus agentStatus = cache.findOneAgentStatusByAgentnoAndOrig(
|
||||
user.getId(), super.getOrgiByTenantshare(request));
|
||||
|
||||
// TODO 因为一个用户可以包含在多个技能组中,所以,skill应该对应
|
||||
// 一个List列表,此处需要重构Skill为列表
|
||||
if (agentStatus != null) {
|
||||
userProxy.attachOrgansPropertiesForUser(user);
|
||||
agentStatus.setSkills(user.getSkills());
|
||||
cache.putAgentStatusByOrgi(agentStatus, super.getOrgiByTenantshare(request));
|
||||
}
|
||||
}
|
||||
}
|
||||
userRepository.save(organUserList);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ));
|
||||
}
|
||||
|
||||
@RequestMapping("/user/delete")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView userroledelete(
|
||||
final HttpServletRequest request,
|
||||
final @Valid String id,
|
||||
final @Valid String organ
|
||||
) {
|
||||
logger.info("[userroledelete] user id {}, organ {}", id, organ);
|
||||
if (id != null) {
|
||||
organUserRes.deleteOrganUserByUseridAndOrgan(id, organ);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("/admin/organ/edit"));
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
view.addObject("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)));
|
||||
|
||||
map.addAttribute(
|
||||
"organList", organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView update(HttpServletRequest request, @Valid Organ organ) {
|
||||
String msg = organProxy.updateOrgan(organ, super.getOrgi(request), super.getUser(request));
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + organ.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping("/area")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView area(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC);
|
||||
if (sysDic != null) {
|
||||
map.addAttribute("sysarea", sysDic);
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId()));
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC));
|
||||
|
||||
map.addAttribute("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)));
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/area"));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/area/update")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView areaupdate(HttpServletRequest request, @Valid Organ organ) {
|
||||
Organ tempOrgan = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request));
|
||||
String msg = "admin_organ_update_success";
|
||||
if (tempOrgan != null) {
|
||||
tempOrgan.setArea(organ.getArea());
|
||||
organRepository.save(tempOrgan);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
} else {
|
||||
msg = "admin_organ_update_not_exist";
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + organ.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid Organ organ) {
|
||||
String msg = "admin_organ_delete";
|
||||
|
||||
Organ organSelf = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request));
|
||||
List<Organ> organParentAre = organRepository.findByOrgiAndParent(organSelf.getOrgi(), organSelf.getId());
|
||||
if (organ != null && organParentAre != null && organParentAre.size() > 0) {
|
||||
msg = "admin_oran_not_delete";
|
||||
} else if (organ != null) {
|
||||
List<OrganUser> organUsers = organUserRes.findByOrgan(organ.getId());
|
||||
organUserRes.deleteInBatch(organUsers);
|
||||
organRepository.delete(organ);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
} else {
|
||||
msg = "admin_organ_not_exist";
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?msg=" + msg));
|
||||
}
|
||||
|
||||
@RequestMapping("/auth/save")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView authsave(HttpServletRequest request, @Valid String id, @Valid String menus) {
|
||||
Organ organData = organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request));
|
||||
List<OrganRole> organRoleList = organRoleRes.findByOrgiAndOrgan(super.getOrgiByTenantshare(request), organData);
|
||||
organRoleRes.delete(organRoleList);
|
||||
if (!StringUtils.isBlank(menus)) {
|
||||
String[] menusarray = menus.split(",");
|
||||
for (String menu : menusarray) {
|
||||
OrganRole organRole = new OrganRole();
|
||||
SysDic sysDic = Dict.getInstance().getDicItem(menu);
|
||||
if (sysDic != null && !"0".equals(sysDic.getParentid())) {
|
||||
organRole.setDicid(menu);
|
||||
organRole.setDicvalue(sysDic.getCode());
|
||||
|
||||
organRole.setOrgan(organData);
|
||||
organRole.setCreater(super.getUser(request).getId());
|
||||
organRole.setOrgi(super.getOrgiByTenantshare(request));
|
||||
organRole.setCreatetime(new Date());
|
||||
organRoleRes.save(organRole);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return request(
|
||||
super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organData.getId()));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainContext;
|
||||
import com.chatopera.cc.cache.Cache;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.*;
|
||||
import com.chatopera.cc.persistence.repository.*;
|
||||
import com.chatopera.cc.proxy.OnlineUserProxy;
|
||||
import com.chatopera.cc.proxy.OrganProxy;
|
||||
import com.chatopera.cc.proxy.UserProxy;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="http://blog.didispace.com">程序猿DD</a>
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/admin/organ")
|
||||
public class OrganController extends Handler {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(OrganController.class);
|
||||
|
||||
@NonNull
|
||||
private final OrganRepository organRepository;
|
||||
|
||||
@NonNull
|
||||
private final OrganUserRepository organUserRes;
|
||||
|
||||
@NonNull
|
||||
private final RoleRepository roleRepository;
|
||||
|
||||
@NonNull
|
||||
private final SysDicRepository sysDicRepository;
|
||||
|
||||
@NonNull
|
||||
private final AreaTypeRepository areaRepository;
|
||||
|
||||
@NonNull
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@NonNull
|
||||
private final OrganRoleRepository organRoleRes;
|
||||
|
||||
@NonNull
|
||||
private final OrganProxy organProxy;
|
||||
|
||||
@NonNull
|
||||
private final Cache cache;
|
||||
|
||||
@NonNull
|
||||
private final UserProxy userProxy;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String organ, @Valid String msg) {
|
||||
List<Organ> organList = organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request), super.getOrgid(request));
|
||||
map.addAttribute("organList", organList);
|
||||
if (organList.size() > 0) {
|
||||
Organ organData = null;
|
||||
if (!StringUtils.isBlank(organ) && !"null".equals(organ)) {
|
||||
for (Organ data : organList) {
|
||||
if (data.getId().equals(organ)) {
|
||||
map.addAttribute("organData", data);
|
||||
organData = data;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
map.addAttribute("organData", organData = organList.get(0));
|
||||
}
|
||||
if (organData != null) {
|
||||
map.addAttribute(
|
||||
"userList", userProxy.findByOrganAndOrgiAndDatastatus(
|
||||
organData.getId(),
|
||||
super.getOrgiByTenantshare(request),
|
||||
false));
|
||||
}
|
||||
}
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
map.addAttribute(
|
||||
"roleList", roleRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
map.put("msg", msg);
|
||||
return request(super.createAdminTempletResponse("/admin/organ/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String parent, @Valid String area) {
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
if (!StringUtils.isBlank(parent)) {
|
||||
map.addAttribute("organ", organRepository.findByIdAndOrgi(parent, super.getOrgiByTenantshare(request)));
|
||||
}
|
||||
if (!StringUtils.isBlank(area)) {
|
||||
map.addAttribute("area", areaRepository.findByIdAndOrgi(area, super.getOrgiByTenantshare(request)));
|
||||
}
|
||||
|
||||
map.addAttribute(
|
||||
"organList", organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/add"));
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView save(HttpServletRequest request, @Valid Organ organ) {
|
||||
Organ tempOrgan = organRepository.findByNameAndOrgiAndOrgid(
|
||||
organ.getName(), super.getOrgiByTenantshare(request), super.getOrgid(request));
|
||||
String msg = "admin_organ_new_success";
|
||||
String firstId = null;
|
||||
if (tempOrgan != null) {
|
||||
msg = "admin_organ_update_name_not"; //分类名字重复
|
||||
} else {
|
||||
organ.setOrgi(super.getOrgiByTenantshare(request));
|
||||
|
||||
if (!StringUtils.isBlank(super.getUser(request).getOrgid())) {
|
||||
organ.setOrgid(super.getUser(request).getOrgid());
|
||||
} else {
|
||||
organ.setOrgid(MainContext.SYSTEM_ORGI);
|
||||
}
|
||||
firstId = organ.getId();
|
||||
|
||||
organRepository.save(organ);
|
||||
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + firstId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户到当前部门时选择坐席
|
||||
*/
|
||||
@RequestMapping("/seluser")
|
||||
@Menu(type = "admin", subtype = "seluser", admin = true)
|
||||
public ModelAndView seluser(ModelMap map, HttpServletRequest request, @Valid String organ) {
|
||||
map.addAttribute(
|
||||
"userList", userRepository.findByOrgiAndDatastatusAndOrgid(super.getOrgiByTenantshare(request), false,
|
||||
super.getOrgid(request)));
|
||||
Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request));
|
||||
map.addAttribute("userOrganList", userProxy
|
||||
.findByOrganAndOrgiAndDatastatus(organ, super.getOrgiByTenantshare(request), false));
|
||||
map.addAttribute("organ", organData);
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/seluser"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行添加用户到组织中
|
||||
*/
|
||||
@RequestMapping("/saveuser")
|
||||
@Menu(type = "admin", subtype = "saveuser", admin = true)
|
||||
public ModelAndView saveuser(
|
||||
HttpServletRequest request,
|
||||
final @Valid String[] users,
|
||||
final @Valid String organ
|
||||
) {
|
||||
logger.info("[saveuser] save users {} into organ {}", StringUtils.join(users, ","), organ);
|
||||
final User loginUser = super.getUser(request);
|
||||
|
||||
if (users != null && users.length > 0) {
|
||||
List<String> chosen = new ArrayList<>(Arrays.asList(users));
|
||||
Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgiByTenantshare(request));
|
||||
List<User> organUserList = userRepository.findAllById(chosen);
|
||||
for (final User user : organUserList) {
|
||||
OrganUser ou = organUserRes.findByUseridAndOrgan(user.getId(), organ);
|
||||
|
||||
/*
|
||||
* 检查人员和技能组关系
|
||||
*/
|
||||
if (organData.isSkill()) {
|
||||
// 该组织机构是技能组
|
||||
if (!user.isAgent()) {
|
||||
// 该人员不是坐席
|
||||
if (ou != null) {
|
||||
organUserRes.delete(ou);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ou == null) {
|
||||
ou = new OrganUser();
|
||||
}
|
||||
|
||||
ou.setCreator(loginUser.getId());
|
||||
ou.setUserid(user.getId());
|
||||
ou.setOrgan(organ);
|
||||
|
||||
organUserRes.save(ou);
|
||||
|
||||
if (user.isAgent()) {
|
||||
/*
|
||||
* 以下更新技能组状态
|
||||
*/
|
||||
AgentStatus agentStatus = cache.findOneAgentStatusByAgentnoAndOrig(
|
||||
user.getId(), super.getOrgiByTenantshare(request));
|
||||
|
||||
// TODO 因为一个用户可以包含在多个技能组中,所以,skill应该对应
|
||||
// 一个List列表,此处需要重构Skill为列表
|
||||
if (agentStatus != null) {
|
||||
userProxy.attachOrgansPropertiesForUser(user);
|
||||
agentStatus.setSkills(user.getSkills());
|
||||
cache.putAgentStatusByOrgi(agentStatus, super.getOrgiByTenantshare(request));
|
||||
}
|
||||
}
|
||||
}
|
||||
userRepository.saveAll(organUserList);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ));
|
||||
}
|
||||
|
||||
@RequestMapping("/user/delete")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView userroledelete(
|
||||
final HttpServletRequest request,
|
||||
final @Valid String id,
|
||||
final @Valid String organ
|
||||
) {
|
||||
logger.info("[userroledelete] user id {}, organ {}", id, organ);
|
||||
if (id != null) {
|
||||
organUserRes.deleteOrganUserByUseridAndOrgan(id, organ);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organ));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("/admin/organ/edit"));
|
||||
map.addAttribute("areaList", areaRepository.findByOrgi(super.getOrgiByTenantshare(request)));
|
||||
view.addObject("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)));
|
||||
|
||||
map.addAttribute(
|
||||
"organList", organRepository.findByOrgiAndOrgid(
|
||||
super.getOrgiByTenantshare(request),
|
||||
super.getOrgid(request)));
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView update(HttpServletRequest request, @Valid Organ organ) {
|
||||
String msg = organProxy.updateOrgan(organ, super.getOrgi(request), super.getUser(request));
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + organ.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping("/area")
|
||||
@Menu(type = "admin", subtype = "area")
|
||||
public ModelAndView area(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
|
||||
SysDic sysDic = sysDicRepository.findByCode(Constants.CSKEFU_SYSTEM_AREA_DIC);
|
||||
if (sysDic != null) {
|
||||
map.addAttribute("sysarea", sysDic);
|
||||
map.addAttribute("areaList", sysDicRepository.findByDicid(sysDic.getId()));
|
||||
}
|
||||
map.addAttribute("cacheList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_AREA_DIC));
|
||||
|
||||
map.addAttribute("organData", organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)));
|
||||
return request(super.createRequestPageTempletResponse("/admin/organ/area"));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/area/update")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView areaupdate(HttpServletRequest request, @Valid Organ organ) {
|
||||
Organ tempOrgan = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request));
|
||||
String msg = "admin_organ_update_success";
|
||||
if (tempOrgan != null) {
|
||||
tempOrgan.setArea(organ.getArea());
|
||||
organRepository.save(tempOrgan);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
} else {
|
||||
msg = "admin_organ_update_not_exist";
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + organ.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin", subtype = "organ")
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid Organ organ) {
|
||||
String msg = "admin_organ_delete";
|
||||
|
||||
if (organ != null) {
|
||||
Organ organSelf = organRepository.findByIdAndOrgi(organ.getId(), super.getOrgiByTenantshare(request));
|
||||
List<Organ> organParentAre = organRepository.findByOrgiAndParent(organSelf.getOrgi(), organSelf.getId());
|
||||
if (organParentAre != null && organParentAre.size() > 0) {
|
||||
msg = "admin_oran_not_delete";
|
||||
} else {
|
||||
List<OrganUser> organUsers = organUserRes.findByOrgan(organ.getId());
|
||||
organUserRes.deleteInBatch(organUsers);
|
||||
organRepository.delete(organ);
|
||||
OnlineUserProxy.clean(super.getOrgi(request));
|
||||
}
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?msg=" + msg));
|
||||
}
|
||||
|
||||
@RequestMapping("/auth/save")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView authsave(HttpServletRequest request, @Valid String id, @Valid String menus) {
|
||||
Organ organData = organRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request));
|
||||
List<OrganRole> organRoleList = organRoleRes.findByOrgiAndOrgan(super.getOrgiByTenantshare(request), organData);
|
||||
organRoleRes.deleteAll(organRoleList);
|
||||
if (!StringUtils.isBlank(menus)) {
|
||||
String[] menusarray = menus.split(",");
|
||||
for (String menu : menusarray) {
|
||||
OrganRole organRole = new OrganRole();
|
||||
SysDic sysDic = Dict.getInstance().getDicItem(menu);
|
||||
if (sysDic != null && !"0".equals(sysDic.getParentid())) {
|
||||
organRole.setDicid(menu);
|
||||
organRole.setDicvalue(sysDic.getCode());
|
||||
|
||||
organRole.setOrgan(organData);
|
||||
organRole.setCreater(super.getUser(request).getId());
|
||||
organRole.setOrgi(super.getOrgiByTenantshare(request));
|
||||
organRole.setCreatetime(new Date());
|
||||
organRoleRes.save(organRole);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return request(
|
||||
super.createRequestPageTempletResponse("redirect:/admin/organ/index.html?organ=" + organData.getId()));
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,12 @@ import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.*;
|
||||
import com.chatopera.cc.persistence.repository.*;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -38,25 +39,26 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/admin/role")
|
||||
public class RoleController extends Handler {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(RoleController.class);
|
||||
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
@NonNull
|
||||
private final RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRoleRepository userRoleRes;
|
||||
@NonNull
|
||||
private final UserRoleRepository userRoleRes;
|
||||
|
||||
@Autowired
|
||||
private RoleAuthRepository roleAuthRes;
|
||||
@NonNull
|
||||
private final RoleAuthRepository roleAuthRes;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@NonNull
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository sysDicRes;
|
||||
@NonNull
|
||||
private final SysDicRepository sysDicRes;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
@ -85,7 +87,7 @@ public class RoleController extends Handler {
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView add(ModelMap map, HttpServletRequest request) {
|
||||
public ModelAndView add() {
|
||||
return request(super.createRequestPageTempletResponse("/admin/role/add"));
|
||||
}
|
||||
|
||||
@ -135,10 +137,10 @@ public class RoleController extends Handler {
|
||||
for (UserRole userRole : userRoleList) {
|
||||
if (user.equals(userRole.getUser().getId())) {
|
||||
exist = true;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exist == false) {
|
||||
if (!exist) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUser(new User(user));
|
||||
userRole.setRole(new Role(role));
|
||||
@ -153,16 +155,16 @@ public class RoleController extends Handler {
|
||||
|
||||
@RequestMapping("/user/delete")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView userroledelete(HttpServletRequest request, @Valid String id, @Valid String role) {
|
||||
public ModelAndView userroledelete(@Valid String id, @Valid String role) {
|
||||
if (role != null) {
|
||||
userRoleRes.delete(id);
|
||||
userRoleRes.deleteById(id);
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/role/index.html?role=" + role));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "role")
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) {
|
||||
public ModelAndView edit(HttpServletRequest request, @Valid String id) {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("/admin/role/edit"));
|
||||
view.addObject("roleData", roleRepository.findByIdAndOrgi(id, super.getOrgiByTenantshare(request)));
|
||||
return view;
|
||||
@ -197,7 +199,7 @@ public class RoleController extends Handler {
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid Role role) {
|
||||
String msg = "admin_role_delete";
|
||||
if (role != null) {
|
||||
userRoleRes.delete(userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), role));
|
||||
userRoleRes.deleteAll(userRoleRes.findByOrgiAndRole(super.getOrgiByTenantshare(request), role));
|
||||
roleRepository.delete(role);
|
||||
} else {
|
||||
msg = "admin_role_not_exist";
|
||||
@ -226,7 +228,7 @@ public class RoleController extends Handler {
|
||||
logger.info("[authsave] id {}, menus {}", id, menus);
|
||||
|
||||
List<RoleAuth> roleAuthList = roleAuthRes.findByRoleidAndOrgi(id, super.getOrgiByTenantshare(request));
|
||||
roleAuthRes.delete(roleAuthList);
|
||||
roleAuthRes.deleteAll(roleAuthList);
|
||||
if (StringUtils.isNotBlank(menus)) {
|
||||
String[] menuarray = menus.split(",");
|
||||
|
||||
|
@ -21,13 +21,16 @@ import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import com.chatopera.cc.persistence.repository.SysDicRepository;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -36,15 +39,14 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/admin/sysdic")
|
||||
public class SysDicController extends Handler {
|
||||
@NonNull
|
||||
private final SysDicRepository sysDicRes;
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository sysDicRes;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
@NonNull
|
||||
private final Cache cache;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
@ -55,7 +57,7 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView add(ModelMap map, HttpServletRequest request) {
|
||||
public ModelAndView add() {
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/sysdic/add"));
|
||||
}
|
||||
|
||||
@ -80,7 +82,7 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
public ModelAndView edit(ModelMap map, @Valid String id, @Valid String p) {
|
||||
map.addAttribute("sysDic", sysDicRes.findById(id));
|
||||
map.addAttribute("p", p);
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/sysdic/edit"));
|
||||
@ -91,7 +93,8 @@ public class SysDicController extends Handler {
|
||||
public ModelAndView update(HttpServletRequest request, @Valid SysDic dic, @Valid String p) {
|
||||
List<SysDic> sysDicList = sysDicRes.findByCodeOrName(dic.getCode(), dic.getName());
|
||||
if (sysDicList.size() == 0 || (sysDicList.size() == 1 && sysDicList.get(0).getId().equals(dic.getId()))) {
|
||||
SysDic sysDic = sysDicRes.findById(dic.getId());
|
||||
SysDic sysDic = sysDicRes.findById(dic.getId())
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Value not found for " + dic.getId()));
|
||||
sysDic.setName(dic.getName());
|
||||
sysDic.setCode(dic.getCode());
|
||||
sysDic.setCtype(dic.getCtype());
|
||||
@ -107,9 +110,10 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView delete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
SysDic sysDic = sysDicRes.findById(id);
|
||||
sysDicRes.delete(sysDicRes.findByDicid(id));
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
SysDic sysDic = sysDicRes.findById(id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Value not found for " + id));
|
||||
sysDicRes.deleteAll(sysDicRes.findByDicid(id));
|
||||
sysDicRes.delete(sysDic);
|
||||
|
||||
reloadSysDicItem(sysDic, super.getOrgi(request));
|
||||
@ -127,7 +131,7 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/dicitem/add")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView dicitemadd(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
public ModelAndView dicitemadd(ModelMap map, @Valid String id, @Valid String p) {
|
||||
map.addAttribute("sysDic", sysDicRes.findById(id));
|
||||
map.addAttribute("p", p);
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/sysdic/dicitemadd"));
|
||||
@ -154,8 +158,6 @@ public class SysDicController extends Handler {
|
||||
|
||||
/**
|
||||
* 更新系统词典缓存
|
||||
* @param dic
|
||||
* @param orgi
|
||||
*/
|
||||
public void reloadSysDicItem(final SysDic dic, final String orgi) {
|
||||
cache.putSysDicByOrgi(dic.getId(), orgi, dic);
|
||||
@ -176,7 +178,7 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/dicitem/batadd")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView dicitembatadd(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
public ModelAndView dicitembatadd(ModelMap map, @Valid String id, @Valid String p) {
|
||||
map.addAttribute("sysDic", sysDicRes.findById(id));
|
||||
map.addAttribute("p", p);
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/sysdic/batadd"));
|
||||
@ -185,11 +187,11 @@ public class SysDicController extends Handler {
|
||||
@RequestMapping("/dicitem/batsave")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView dicitembatsave(HttpServletRequest request, @Valid SysDic sysDic, @Valid String content, @Valid String p) {
|
||||
String[] dicitems = content.split("[\n\r\n]");
|
||||
String[] dicitems = content.split("[\n\r]");
|
||||
int count = 0;
|
||||
String orig = super.getOrgi(request);
|
||||
for (String dicitem : dicitems) {
|
||||
String[] dicValues = dicitem.split("[\t, ;]{1,}");
|
||||
String[] dicValues = dicitem.split("[\t, ;]+");
|
||||
if (dicValues.length == 2 && dicValues[0].length() > 0 && dicValues[1].length() > 0) {
|
||||
SysDic dic = new SysDic();
|
||||
dic.setOrgi(orig);
|
||||
@ -215,7 +217,7 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/dicitem/edit")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView dicitemedit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
public ModelAndView dicitemedit(ModelMap map, @Valid String id, @Valid String p) {
|
||||
map.addAttribute("sysDic", sysDicRes.findById(id));
|
||||
map.addAttribute("p", p);
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/sysdic/dicitemedit"));
|
||||
@ -227,7 +229,8 @@ public class SysDicController extends Handler {
|
||||
List<SysDic> sysDicList = sysDicRes.findByDicidAndName(dic.getDicid(), dic.getName());
|
||||
String orgi = super.getOrgi(request);
|
||||
if (sysDicList.size() == 0 || (sysDicList.size() == 1 && sysDicList.get(0).getId().equals(dic.getId()))) {
|
||||
SysDic sysDic = sysDicRes.findById(dic.getId());
|
||||
SysDic sysDic = sysDicRes.findById(dic.getId())
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Value not found for " + dic.getId()));
|
||||
sysDic.setName(dic.getName());
|
||||
sysDic.setCode(dic.getCode());
|
||||
sysDic.setCtype(dic.getCtype());
|
||||
@ -245,8 +248,8 @@ public class SysDicController extends Handler {
|
||||
|
||||
@RequestMapping("/dicitem/delete")
|
||||
@Menu(type = "admin", subtype = "sysdic")
|
||||
public ModelAndView dicitemdelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
sysDicRes.delete(sysDicRes.findByDicid(id));
|
||||
public ModelAndView dicitemdelete(HttpServletRequest request, @Valid String id, @Valid String p) {
|
||||
sysDicRes.deleteAll(sysDicRes.findByDicid(id));
|
||||
SysDic dic = sysDicRes.getOne(id);
|
||||
sysDicRes.delete(dic);
|
||||
reloadSysDicItem(dic, super.getOrgi(request));
|
||||
|
@ -1,192 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin.system;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainUtils;
|
||||
import com.chatopera.cc.cache.Cache;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.Dict;
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import com.chatopera.cc.model.Template;
|
||||
import com.chatopera.cc.persistence.repository.SysDicRepository;
|
||||
import com.chatopera.cc.persistence.repository.TemplateRepository;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import org.apache.commons.lang3.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.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin/template")
|
||||
public class TemplateController extends Handler{
|
||||
|
||||
|
||||
@Autowired
|
||||
private TemplateRepository templateRes;
|
||||
|
||||
@Autowired
|
||||
private SysDicRepository dicRes;
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView index(ModelMap map , HttpServletRequest request) {
|
||||
map.addAttribute("sysDicList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC));
|
||||
return request(super.createAdminTempletResponse("/admin/system/template/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/expall")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public void expall(ModelMap map , HttpServletRequest request , HttpServletResponse response) throws Exception {
|
||||
List<Template> templateList = templateRes.findByOrgi(super.getOrgi(request)) ;
|
||||
response.setHeader("content-disposition", "attachment;filename=UCKeFu-Template-Export-"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())+".data");
|
||||
response.getOutputStream().write(MainUtils.toBytes(templateList));
|
||||
return ;
|
||||
}
|
||||
|
||||
@RequestMapping("/imp")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView imp(ModelMap map , HttpServletRequest request) {
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/imp"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping("/impsave")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView impsave(ModelMap map , HttpServletRequest request , @RequestParam(value = "dataFile", required = false) MultipartFile dataFile) throws Exception {
|
||||
if(dataFile!=null && dataFile.getSize() > 0){
|
||||
List<Template> templateList = (List<Template>) MainUtils.toObject(dataFile.getBytes()) ;
|
||||
if(templateList!=null && templateList.size() >0){
|
||||
templateRes.deleteInBatch(templateList);
|
||||
for(Template template : templateList){
|
||||
templateRes.save(template) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView list(ModelMap map , HttpServletRequest request ,@Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("templateList", templateRes.findByTemplettypeAndOrgi(type, super.getOrgi(request)));
|
||||
return request(super.createAdminTempletResponse("/admin/system/template/list"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView add(ModelMap map , HttpServletRequest request ,@Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/add"));
|
||||
}
|
||||
|
||||
@RequestMapping( "/save")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView save(HttpServletRequest request , @Valid Template template) {
|
||||
template.setOrgi(super.getOrgi(request));
|
||||
template.setCreatetime(new Date());
|
||||
|
||||
SysDic dic = dicRes.findById(template.getTemplettype());
|
||||
if(dic!=null && StringUtils.isBlank(template.getCode())) {
|
||||
template.setCode(dic.getCode());
|
||||
}
|
||||
templateRes.save(template) ;
|
||||
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type="+template.getTemplettype()));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView edit(ModelMap map , HttpServletRequest request , @Valid String id, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("template", templateRes.findByIdAndOrgi(id, super.getOrgi(request))) ;
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/edit"));
|
||||
}
|
||||
|
||||
@RequestMapping( "/update")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView update(HttpServletRequest request , @Valid Template template) {
|
||||
Template oldTemplate = templateRes.findByIdAndOrgi(template.getId(), super.getOrgi(request)) ;
|
||||
if(oldTemplate!=null){
|
||||
SysDic dic = dicRes.findById(oldTemplate.getTemplettype());
|
||||
if(dic!=null) {
|
||||
oldTemplate.setCode(dic.getCode());
|
||||
}
|
||||
if(!StringUtils.isBlank(template.getCode())) {
|
||||
oldTemplate.setCode(template.getCode());
|
||||
}
|
||||
oldTemplate.setName(template.getName());
|
||||
oldTemplate.setLayoutcols(template.getLayoutcols());
|
||||
oldTemplate.setIconstr(template.getIconstr());
|
||||
oldTemplate.setDatatype(template.getDatatype());
|
||||
oldTemplate.setCharttype(template.getCharttype());
|
||||
templateRes.save(oldTemplate) ;
|
||||
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type="+template.getTemplettype()));
|
||||
}
|
||||
|
||||
@RequestMapping("/code")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView code(ModelMap map , HttpServletRequest request , @Valid String id, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("template", templateRes.findByIdAndOrgi(id, super.getOrgi(request))) ;
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/code"));
|
||||
}
|
||||
|
||||
@RequestMapping( "/codesave")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView codesave(HttpServletRequest request , @Valid Template template) {
|
||||
Template oldTemplate = templateRes.findByIdAndOrgi(template.getId(), super.getOrgi(request)) ;
|
||||
if(oldTemplate!=null){
|
||||
oldTemplate.setTemplettext(template.getTemplettext());
|
||||
oldTemplate.setTemplettitle(template.getTemplettitle());
|
||||
templateRes.save(oldTemplate) ;
|
||||
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type="+template.getTemplettype()));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin" , subtype = "template" , access = false , admin = true)
|
||||
public ModelAndView delete(HttpServletRequest request ,@Valid Template template) {
|
||||
if(template!=null){
|
||||
templateRes.delete(template) ;
|
||||
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type="+template.getTemplettype()));
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.controller.admin.system;
|
||||
|
||||
import com.chatopera.cc.basic.Constants;
|
||||
import com.chatopera.cc.basic.MainUtils;
|
||||
import com.chatopera.cc.cache.Cache;
|
||||
import com.chatopera.cc.controller.Handler;
|
||||
import com.chatopera.cc.model.Dict;
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import com.chatopera.cc.model.Template;
|
||||
import com.chatopera.cc.persistence.repository.SysDicRepository;
|
||||
import com.chatopera.cc.persistence.repository.TemplateRepository;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.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.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/admin/template")
|
||||
public class TemplateController extends Handler {
|
||||
|
||||
@NonNull
|
||||
private final TemplateRepository templateRes;
|
||||
|
||||
@NonNull
|
||||
private final SysDicRepository dicRes;
|
||||
|
||||
@NonNull
|
||||
private final Cache cache;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request) {
|
||||
map.addAttribute("sysDicList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC));
|
||||
return request(super.createAdminTempletResponse("/admin/system/template/index"));
|
||||
}
|
||||
|
||||
@RequestMapping("/expall")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public void expall(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
List<Template> templateList = templateRes.findByOrgi(super.getOrgi(request));
|
||||
response.setHeader("content-disposition", "attachment;filename=UCKeFu-Template-Export-" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + ".data");
|
||||
response.getOutputStream().write(MainUtils.toBytes(templateList));
|
||||
return;
|
||||
}
|
||||
|
||||
@RequestMapping("/imp")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView imp(ModelMap map, HttpServletRequest request) {
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/imp"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping("/impsave")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView impsave(ModelMap map, HttpServletRequest request, @RequestParam(value = "dataFile", required = false) MultipartFile dataFile) throws Exception {
|
||||
if (dataFile != null && dataFile.getSize() > 0) {
|
||||
List<Template> templateList = (List<Template>) MainUtils.toObject(dataFile.getBytes());
|
||||
if (templateList != null && templateList.size() > 0) {
|
||||
templateRes.deleteInBatch(templateList);
|
||||
for (Template template : templateList) {
|
||||
templateRes.save(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/index.html"));
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView list(ModelMap map, HttpServletRequest request, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("templateList", templateRes.findByTemplettypeAndOrgi(type, super.getOrgi(request)));
|
||||
return request(super.createAdminTempletResponse("/admin/system/template/list"));
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/add"));
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView save(HttpServletRequest request, @Valid Template template) {
|
||||
template.setOrgi(super.getOrgi(request));
|
||||
template.setCreatetime(new Date());
|
||||
|
||||
String dicId = template.getTemplettype();
|
||||
SysDic dic = dicRes.findById(dicId).orElse(null);
|
||||
if (dic != null && StringUtils.isBlank(template.getCode())) {
|
||||
template.setCode(dic.getCode());
|
||||
}
|
||||
templateRes.save(template);
|
||||
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type=" + dicId));
|
||||
}
|
||||
|
||||
@RequestMapping("/edit")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("template", templateRes.findByIdAndOrgi(id, super.getOrgi(request)));
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/edit"));
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView update(HttpServletRequest request, @Valid Template template) {
|
||||
Template oldTemplate = templateRes.findByIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
if (oldTemplate != null) {
|
||||
String dicId = oldTemplate.getTemplettype();
|
||||
dicRes.findById(dicId).ifPresent(dic -> oldTemplate.setCode(dic.getCode()));
|
||||
if (!StringUtils.isBlank(template.getCode())) {
|
||||
oldTemplate.setCode(template.getCode());
|
||||
}
|
||||
oldTemplate.setName(template.getName());
|
||||
oldTemplate.setLayoutcols(template.getLayoutcols());
|
||||
oldTemplate.setIconstr(template.getIconstr());
|
||||
oldTemplate.setDatatype(template.getDatatype());
|
||||
oldTemplate.setCharttype(template.getCharttype());
|
||||
templateRes.save(oldTemplate);
|
||||
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type=" + template.getTemplettype()));
|
||||
}
|
||||
|
||||
@RequestMapping("/code")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView code(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String type) {
|
||||
map.addAttribute("sysDic", dicRes.findById(type));
|
||||
map.addAttribute("template", templateRes.findByIdAndOrgi(id, super.getOrgi(request)));
|
||||
return request(super.createRequestPageTempletResponse("/admin/system/template/code"));
|
||||
}
|
||||
|
||||
@RequestMapping("/codesave")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView codesave(HttpServletRequest request, @Valid Template template) {
|
||||
Template oldTemplate = templateRes.findByIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
if (oldTemplate != null) {
|
||||
oldTemplate.setTemplettext(template.getTemplettext());
|
||||
oldTemplate.setTemplettitle(template.getTemplettitle());
|
||||
templateRes.save(oldTemplate);
|
||||
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
}
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type=" + template.getTemplettype()));
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@Menu(type = "admin", subtype = "template", access = false, admin = true)
|
||||
public ModelAndView delete(HttpServletRequest request, @Valid Template template) {
|
||||
templateRes.delete(template);
|
||||
cache.deleteSystembyIdAndOrgi(template.getId(), super.getOrgi(request));
|
||||
return request(super.createRequestPageTempletResponse("redirect:/admin/template/list.html?type=" + template.getTemplettype()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.persistence.repository;
|
||||
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysDicRepository extends JpaRepository<SysDic, String>{
|
||||
|
||||
|
||||
SysDic findById(String id);
|
||||
|
||||
SysDic findByCode(String code);
|
||||
|
||||
Page<SysDic> findAll(Pageable paramPageable);
|
||||
|
||||
List<SysDic> findByCodeOrName(String code, String name);
|
||||
|
||||
List<SysDic> findByDicidAndName(String dicid, String name);
|
||||
|
||||
Page<SysDic> findByParentid(String type, Pageable paramPageable);
|
||||
|
||||
List<SysDic> findByParentid(String type);
|
||||
|
||||
List<SysDic> findByDicid(String id);
|
||||
|
||||
int countByName(String name);
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.chatopera.cc.persistence.repository;
|
||||
|
||||
import com.chatopera.cc.model.SysDic;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysDicRepository extends JpaRepository<SysDic, String> {
|
||||
|
||||
|
||||
// SysDic findById(String id);
|
||||
|
||||
SysDic findByCode(String code);
|
||||
|
||||
Page<SysDic> findAll(Pageable paramPageable);
|
||||
|
||||
List<SysDic> findByCodeOrName(String code, String name);
|
||||
|
||||
List<SysDic> findByDicidAndName(String dicid, String name);
|
||||
|
||||
Page<SysDic> findByParentid(String type, Pageable paramPageable);
|
||||
|
||||
List<SysDic> findByParentid(String type);
|
||||
|
||||
List<SysDic> findByDicid(String id);
|
||||
|
||||
int countByName(String name);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user