From 466f2454e8beb6ef2307c882aff627eb27c6a27f Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Tue, 29 Apr 2025 10:21:00 +0800 Subject: [PATCH] bug 5801 --- .../core/alloc/mapper/AllocCanteenMapper.java | 2 ++ .../service/impl/AllocCanteenServiceImpl.java | 19 +++++++++++++------ .../mapper/alloc/AllocCanteenMapper.xml | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/mapper/AllocCanteenMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/mapper/AllocCanteenMapper.java index 60a940a..6356cc7 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/mapper/AllocCanteenMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/mapper/AllocCanteenMapper.java @@ -18,6 +18,8 @@ public interface AllocCanteenMapper { */ public AllocCanteen selectAllocCanteenByCanteenId(Long canteenId); + public AllocCanteen selectAllocCanteenByCanteenName(String canteenName); + /** * 查询食堂信息列表 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/service/impl/AllocCanteenServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/service/impl/AllocCanteenServiceImpl.java index 4d4f787..c54b35f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/service/impl/AllocCanteenServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/alloc/service/impl/AllocCanteenServiceImpl.java @@ -7,10 +7,7 @@ import java.util.stream.Collectors; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.bonus.canteen.core.alloc.domain.AllocCanteen; -import com.bonus.canteen.core.alloc.domain.AllocStall; -import com.bonus.canteen.core.alloc.domain.AppletReserveCanteenVO; -import com.bonus.canteen.core.alloc.domain.AppletReserveStallVO; +import com.bonus.canteen.core.alloc.domain.*; import com.bonus.canteen.core.alloc.mapper.AllocCanteenMapper; import com.bonus.canteen.core.utils.BnsConstants; import com.bonus.common.core.exception.ServiceException; @@ -65,9 +62,13 @@ public class AllocCanteenServiceImpl implements IAllocCanteenService { allocCanteen.setCreateTime(DateUtils.getNowDate()); allocCanteen.setIfReserve(BnsConstants.COMMON_YES); //默认开启预订餐 try { + AllocCanteen checkResult = allocCanteenMapper.selectAllocCanteenByCanteenName(allocCanteen.getCanteenName()); + if (Objects.nonNull(checkResult)) { + throw new ServiceException("食堂名称已存在"); + } return allocCanteenMapper.insertAllocCanteen(allocCanteen); } catch (Exception e) { - throw new ServiceException("错误信息描述"); + throw new ServiceException("新增食堂异常," + e.getMessage()); } } @@ -81,9 +82,15 @@ public class AllocCanteenServiceImpl implements IAllocCanteenService { public int updateAllocCanteen(AllocCanteen allocCanteen) { allocCanteen.setUpdateTime(DateUtils.getNowDate()); try { + List allCanteenList = allocCanteenMapper.selectAllocCanteenList(new AllocCanteen()); + List otherCanteenNameList = allCanteenList.stream().filter(item -> !item.getCanteenId().equals(allocCanteen.getCanteenId())) + .map(AllocCanteen::getCanteenName).collect(Collectors.toList()); + if (otherCanteenNameList.contains(allocCanteen.getCanteenName())) { + throw new ServiceException("食堂名称已存在"); + } return allocCanteenMapper.updateAllocCanteen(allocCanteen); } catch (Exception e) { - throw new ServiceException("错误信息描述"); + throw new ServiceException("更新食堂异常," + e.getMessage()); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocCanteenMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocCanteenMapper.xml index 1b8b805..039bfae 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocCanteenMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocCanteenMapper.xml @@ -70,6 +70,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where ac.canteen_id = #{canteenId} + + insert into alloc_canteen