From 5837db1bfdccc259bdec1a5183979990a569f1ad Mon Sep 17 00:00:00 2001 From: "dengchao@xgtl" <2325690622@qq.com> Date: Fri, 17 Apr 2020 11:12:44 +0800 Subject: [PATCH] Fix IMGroupRepository related class --- .../cc/controller/apps/EntIMController.java | 13 ++-- .../repository/IMGroupRepository.java | 61 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/EntIMController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/EntIMController.java index fdee8d70..b2f78995 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/EntIMController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/EntIMController.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; +import org.springframework.http.HttpStatus; import org.springframework.lang.NonNull; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -44,6 +45,7 @@ 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.server.ResponseStatusException; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; @@ -230,7 +232,7 @@ public class EntIMController extends Handler { @Menu(type = "im", subtype = "entim") public ModelAndView groupMore(HttpServletRequest request, @Valid String id) { ModelAndView view = request(super.createEntIMTempletResponse("/apps/entim/group/index")); - IMGroup imGroup = imGroupRes.findById(id); + IMGroup imGroup = imGroupRes.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("IMGroup %s not found", id))); view.addObject("imGroup", imGroup); view.addObject("imGroupUserList", imGroupUserRes.findByImgroupAndOrgi(imGroup, super.getOrgi(request))); view.addObject("contextid", id); @@ -264,7 +266,7 @@ public class EntIMController extends Handler { users.forEach(userProxy::attachOrgansPropertiesForUser); view.addObject("userList", users); - IMGroup imGroup = imGroupRes.findById(id); + IMGroup imGroup = imGroupRes.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("IMGroup %s not found", id))); List organs = organRes.findAllById(affiliates); view.addObject("imGroup", imGroup); @@ -318,12 +320,11 @@ public class EntIMController extends Handler { @Valid String tipmsg ) { ModelAndView view = request(super.createRequestPageTempletResponse("/apps/entim/group/tipmsg")); - IMGroup imGroup = imGroupRes.findById(id); - if (imGroup != null) { + imGroupRes.findById(id).ifPresent(imGroup -> { imGroup.setTipmessage(tipmsg); imGroupRes.save(imGroup); - } - view.addObject("imGroup", imGroup); + view.addObject("imGroup", imGroup); + }); return view; } diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/IMGroupRepository.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/IMGroupRepository.java index a4437a2a..a02ad73b 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/IMGroupRepository.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/IMGroupRepository.java @@ -1,31 +1,30 @@ -/* - * 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.IMGroup; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface IMGroupRepository extends - JpaRepository { - IMGroup findById(String id); - - List findByCreaterAndOrgi(String user, String orgi); - - int countByNameAndOrgi(String name, 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.IMGroup; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface IMGroupRepository extends JpaRepository { + // IMGroup findById(String id); + + List findByCreaterAndOrgi(String user, String orgi); + + int countByNameAndOrgi(String name, String orgi); +}