From dd38207c192f70d348283df96cebe76009f4cced Mon Sep 17 00:00:00 2001 From: pnoker Date: Sun, 14 Jun 2020 01:57:58 +0800 Subject: [PATCH] refactor(manager): align GroupClient feign methods with service impl --- .../api/center/manager/feign/GroupClient.java | 10 ++++----- .../service/impl/GroupServiceImpl.java | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/GroupClient.java b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/GroupClient.java index ad527aeab..4baec161f 100644 --- a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/GroupClient.java +++ b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/GroupClient.java @@ -44,7 +44,7 @@ public interface GroupClient { /** * 新增 Group * - * @param group + * @param group Group * @return Group */ @PostMapping("/add") @@ -53,7 +53,7 @@ public interface GroupClient { /** * 根据 ID 删除 Group * - * @param id groupId + * @param id Group Id * @return Boolean */ @PostMapping("/delete/{id}") @@ -62,7 +62,7 @@ public interface GroupClient { /** * 修改 Group * - * @param group + * @param group Group * @return Group */ @PostMapping("/update") @@ -71,7 +71,7 @@ public interface GroupClient { /** * 根据 ID 查询 Group * - * @param id + * @param id Group Id * @return Group */ @GetMapping("/id/{id}") @@ -80,7 +80,7 @@ public interface GroupClient { /** * 分页查询 Group * - * @param groupDto + * @param groupDto Group Dto * @return Page */ @PostMapping("/list") diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java index 18e180b36..2b9ff58d7 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java @@ -20,8 +20,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.dc3.center.manager.mapper.GroupMapper; -import com.dc3.center.manager.service.GroupService; import com.dc3.center.manager.service.DeviceService; +import com.dc3.center.manager.service.GroupService; import com.dc3.common.bean.Pages; import com.dc3.common.constant.Common; import com.dc3.common.dto.DeviceDto; @@ -66,13 +66,13 @@ public class GroupServiceImpl implements GroupService { ) public Group add(Group group) { Group select = selectByName(group.getName()); - if (null != select) { - throw new ServiceException("device group already exists"); - } + Optional.ofNullable(select).ifPresent(g -> { + throw new ServiceException("The device group already exists"); + }); if (groupMapper.insert(group) > 0) { return groupMapper.selectById(group.getId()); } - return null; + throw new ServiceException("The group add failed"); } @Override @@ -89,7 +89,11 @@ public class GroupServiceImpl implements GroupService { deviceDto.setGroupId(id); Page devicePage = deviceService.list(deviceDto); if (devicePage.getTotal() > 0) { - throw new ServiceException("group already bound by the device"); + throw new ServiceException("The group already bound by the device"); + } + Group group = selectById(id); + if (null == group) { + throw new ServiceException("The group does not exist"); } return groupMapper.deleteById(id) > 0; } @@ -106,13 +110,17 @@ public class GroupServiceImpl implements GroupService { } ) public Group update(Group group) { + Group temp = selectById(group.getId()); + if (null == temp) { + throw new ServiceException("The group does not exist"); + } group.setUpdateTime(null); if (groupMapper.updateById(group) > 0) { Group select = selectById(group.getId()); group.setName(select.getName()); return select; } - return null; + throw new ServiceException("The group update failed"); } @Override