diff --git a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java index a03c78579..1bebd1297 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java @@ -86,7 +86,9 @@ public enum ErrorCodeEnum { INSPECTION_INFO_NOT_EXIST(600005, "稽核信息不存在!", null), OPEN_AREA_NULL(600006,"归属地区不能为空",null), - OUTBOUND_NUMBER_EXIST(110001, "手机号已存在!", null); + OUTBOUND_NUMBER_EXIST(110001, "手机号已存在!", null), + + LABEL_GROUP_IN_USE(120001, "请勿删除仍在使用的标签组!", null); ; diff --git a/coolstore-partner-dao/src/main/resources/mapper/HyPartnerLabelGroupMapper.xml b/coolstore-partner-dao/src/main/resources/mapper/HyPartnerLabelGroupMapper.xml index 1a0b45c2b..7e828ab6f 100644 --- a/coolstore-partner-dao/src/main/resources/mapper/HyPartnerLabelGroupMapper.xml +++ b/coolstore-partner-dao/src/main/resources/mapper/HyPartnerLabelGroupMapper.xml @@ -28,7 +28,6 @@ select from hy_partner_label_group where deleted = 0 - @@ -191,7 +190,7 @@ SELECT t1.id, t1.label_group_name, t2.`name` AS editName, t2.mobile AS editMobile, t1.edit_date FROM hy_partner_label_group t1 LEFT JOIN enterprise_user t2 ON t1.edit_user_id = t2.user_id - WHERE t1.deleted = 0 AND t2.deleted = 0 + WHERE t1.deleted = 0 AND t1.label_group_name LIKE CONCAT('%', #{labelGroupName}, '%') 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 4c9a44bd7..1cb8686ad 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 @@ -4,6 +4,7 @@ import com.cool.store.dto.label.LabelGroupAddDTO; import com.cool.store.dto.label.LabelGroupDeleteDTO; import com.cool.store.dto.label.LabelGroupListDTO; import com.cool.store.dto.label.LabelGroupUpdateDTO; +import com.cool.store.exception.ApiException; import com.cool.store.vo.LabelGroupListVo; import java.util.List; @@ -36,7 +37,7 @@ public interface LabelGroupService { * 删除标签组 * @param dto 待删除标签组信息 */ - void deleteLabelGroup(LabelGroupDeleteDTO dto); + void deleteLabelGroup(LabelGroupDeleteDTO 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 3028473db..b86d101f6 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 @@ -6,7 +6,10 @@ import com.cool.store.dto.label.LabelGroupDeleteDTO; import com.cool.store.dto.label.LabelGroupListDTO; import com.cool.store.dto.label.LabelGroupUpdateDTO; import com.cool.store.entity.HyPartnerLabelGroupDO; +import com.cool.store.enums.ErrorCodeEnum; +import com.cool.store.exception.ApiException; import com.cool.store.mapper.HyPartnerLabelGroupMapper; +import com.cool.store.mapper.HyPartnerLabelMapper; import com.cool.store.service.LabelGroupService; import com.cool.store.vo.LabelGroupListVo; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +28,9 @@ public class LabelGroupServiceImpl implements LabelGroupService { @Autowired private HyPartnerLabelGroupMapper labelGroupMapper; + @Autowired + private HyPartnerLabelMapper labelMapper; + /** * 查询标签组信息列表 * @param dto 查询条件 @@ -33,7 +39,7 @@ public class LabelGroupServiceImpl implements LabelGroupService { public List getLabelGroupList(LabelGroupListDTO dto) { HyPartnerLabelGroupDO labelGroupDO = new HyPartnerLabelGroupDO(); labelGroupDO.setLabelGroupName(dto.getLabelGroupName()); - return this.labelGroupMapper.getLabelGroupList(labelGroupDO); + return labelGroupMapper.getLabelGroupList(labelGroupDO); } /** @@ -49,7 +55,7 @@ public class LabelGroupServiceImpl implements LabelGroupService { labelGroupDO.setEditDate(new Date()); labelGroupDO.setCreateUserId(userId); labelGroupDO.setUpdateUserId(userId); - this.labelGroupMapper.insertSelective(labelGroupDO); + labelGroupMapper.insertSelective(labelGroupDO); } /** @@ -65,7 +71,7 @@ public class LabelGroupServiceImpl implements LabelGroupService { labelGroupDO.setEditUserId(userId); labelGroupDO.setEditDate(new Date()); labelGroupDO.setUpdateUserId(userId); - this.labelGroupMapper.updateByPrimaryKeySelective(labelGroupDO); + labelGroupMapper.updateByPrimaryKeySelective(labelGroupDO); } /** @@ -73,13 +79,16 @@ public class LabelGroupServiceImpl implements LabelGroupService { * @param dto 待删除标签组信息 */ @Override - public void deleteLabelGroup(LabelGroupDeleteDTO dto) { + public void deleteLabelGroup(LabelGroupDeleteDTO dto) throws ApiException { + if (whetherGroupInUse(dto.getId())) { + throw new ApiException(ErrorCodeEnum.LABEL_GROUP_IN_USE); + } HyPartnerLabelGroupDO labelGroupDO = new HyPartnerLabelGroupDO(); String userId = CurrentUserHolder.getUserId(); labelGroupDO.setId(dto.getId()); labelGroupDO.setDeleted(Boolean.TRUE); labelGroupDO.setUpdateUserId(userId); - this.labelGroupMapper.updateByPrimaryKeySelective(labelGroupDO); + labelGroupMapper.updateByPrimaryKeySelective(labelGroupDO); } /** @@ -88,7 +97,15 @@ public class LabelGroupServiceImpl implements LabelGroupService { @Override public List getAllLabelGroupList() { HyPartnerLabelGroupDO labelGroupDO = new HyPartnerLabelGroupDO(); - return this.labelGroupMapper.getLabelGroupList(labelGroupDO); + return labelGroupMapper.getLabelGroupList(labelGroupDO); + } + + /** + * 某个标签组内是否有未删除的标签 + * @param id 标签组 id + */ + private Boolean whetherGroupInUse(Long id) { + return labelMapper.whetherGroupInUse(id); } } 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 5be3b1eba..6ad86e471 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 @@ -4,6 +4,7 @@ import com.cool.store.dto.label.LabelGroupAddDTO; import com.cool.store.dto.label.LabelGroupDeleteDTO; import com.cool.store.dto.label.LabelGroupListDTO; import com.cool.store.dto.label.LabelGroupUpdateDTO; +import com.cool.store.exception.ApiException; import com.cool.store.response.ResponseResult; import com.cool.store.service.LabelGroupService; import com.cool.store.vo.LabelGroupListVo; @@ -34,35 +35,35 @@ public class LabelGroupController { @PostMapping({"/list"}) public ResponseResult> getLabelGroupList(@RequestBody LabelGroupListDTO dto) { PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); - List result = this.labelGroupService.getLabelGroupList(dto); + List result = labelGroupService.getLabelGroupList(dto); return ResponseResult.success(new PageInfo<>(result)); } @ApiOperation("新增标签组") @PostMapping({"/add"}) public ResponseResult addLabelGroup(@RequestBody LabelGroupAddDTO dto) { - this.labelGroupService.addLabelGroup(dto); + labelGroupService.addLabelGroup(dto); return ResponseResult.success(); } @ApiOperation("修改标签组") @PostMapping({"/edit"}) public ResponseResult updateLabelGroup(@RequestBody LabelGroupUpdateDTO dto) { - this.labelGroupService.updateLabelGroup(dto); + labelGroupService.updateLabelGroup(dto); return ResponseResult.success(); } @ApiOperation("删除标签组") @PostMapping({"/delete"}) - public ResponseResult deleteLabelGroup(@RequestBody LabelGroupDeleteDTO dto) { - this.labelGroupService.deleteLabelGroup(dto); + public ResponseResult deleteLabelGroup(@RequestBody LabelGroupDeleteDTO dto) throws ApiException { + labelGroupService.deleteLabelGroup(dto); return ResponseResult.success(); } @ApiOperation("获取所有标签组") @PostMapping({"/allList"}) public ResponseResult> deleteLabelGroup() { - return ResponseResult.success(this.labelGroupService.getAllLabelGroupList()); + return ResponseResult.success(labelGroupService.getAllLabelGroupList()); } }