From 0d885f8d8f1f58e3321415ac9948cf7cfb474ee6 Mon Sep 17 00:00:00 2001 From: "feng.li" Date: Mon, 21 Aug 2023 17:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=87=E7=AD=BE=E7=BB=84?= =?UTF-8?q?=E5=90=8D=E6=8E=92=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cool/store/service/LabelGroupService.java | 2 +- .../store/service/impl/LabelGroupServiceImpl.java | 15 ++++++++++++--- .../store/controller/LabelGroupController.java | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/LabelGroupService.java b/coolstore-partner-service/src/main/java/com/cool/store/service/LabelGroupService.java index 481528b22..1e2b882c1 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/LabelGroupService.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/LabelGroupService.java @@ -31,7 +31,7 @@ public interface LabelGroupService { * 修改标签组信息 * @param dto 修改内容 */ - void updateLabelGroup(LabelGroupUpdateDTO dto); + void updateLabelGroup(LabelGroupUpdateDTO dto) throws ApiException; /** * 删除标签组 diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/LabelGroupServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/LabelGroupServiceImpl.java index 8d6e671b2..b6336adf4 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/LabelGroupServiceImpl.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/LabelGroupServiceImpl.java @@ -14,6 +14,7 @@ import com.cool.store.service.LabelGroupService; import com.cool.store.vo.LabelGroupListVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @@ -50,8 +51,7 @@ public class LabelGroupServiceImpl implements LabelGroupService { public void addLabelGroup(LabelGroupAddDTO dto) throws ApiException { HyPartnerLabelGroupDO labelGroupDO = new HyPartnerLabelGroupDO(); labelGroupDO.setLabelGroupName(dto.getLabelGroupName()); - List existLabelGroup = labelGroupMapper.selectSelective(labelGroupDO); - if (existLabelGroup != null && existLabelGroup.size() > 0) { + if (whetherGroupDuplicated(labelGroupDO)) { throw new ApiException(ErrorCodeEnum.LABEL_GROUP_EXIST); } String userId = CurrentUserHolder.getUserId(); @@ -67,8 +67,12 @@ public class LabelGroupServiceImpl implements LabelGroupService { * @param dto 修改内容 */ @Override - public void updateLabelGroup(LabelGroupUpdateDTO dto) { + public void updateLabelGroup(LabelGroupUpdateDTO dto) throws ApiException { HyPartnerLabelGroupDO labelGroupDO = new HyPartnerLabelGroupDO(); + labelGroupDO.setLabelGroupName(dto.getLabelGroupName()); + if (whetherGroupDuplicated(labelGroupDO)) { + throw new ApiException(ErrorCodeEnum.LABEL_GROUP_EXIST); + } String userId = CurrentUserHolder.getUserId(); labelGroupDO.setId(dto.getId()); labelGroupDO.setLabelGroupName(dto.getLabelGroupName()); @@ -112,4 +116,9 @@ public class LabelGroupServiceImpl implements LabelGroupService { return labelMapper.whetherGroupInUse(id); } + private Boolean whetherGroupDuplicated(HyPartnerLabelGroupDO labelGroupDO) { + List hyPartnerLabelGroupDOS = labelGroupMapper.selectSelective(labelGroupDO); + return hyPartnerLabelGroupDOS != null && hyPartnerLabelGroupDOS.size() > 0; + } + } diff --git a/coolstore-partner-webb/src/main/java/com/cool/store/controller/LabelGroupController.java b/coolstore-partner-webb/src/main/java/com/cool/store/controller/LabelGroupController.java index c84cfd5cc..da42a6da1 100644 --- a/coolstore-partner-webb/src/main/java/com/cool/store/controller/LabelGroupController.java +++ b/coolstore-partner-webb/src/main/java/com/cool/store/controller/LabelGroupController.java @@ -48,7 +48,7 @@ public class LabelGroupController { @ApiOperation("修改标签组") @PostMapping({"/edit"}) - public ResponseResult updateLabelGroup(@RequestBody LabelGroupUpdateDTO dto) { + public ResponseResult updateLabelGroup(@RequestBody LabelGroupUpdateDTO dto) throws ApiException { labelGroupService.updateLabelGroup(dto); return ResponseResult.success(); }