diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketInfoMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketInfoMapper.java index a284376..fc01bbb 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketInfoMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketInfoMapper.java @@ -28,6 +28,8 @@ public interface SupermarketInfoMapper { */ public List selectSupermarketInfoList(SupermarketInfo supermarketInfo); + public SupermarketInfo selectSupermarketInfoBySupermarketName(SupermarketInfo supermarketInfo); + /** * 新增超市 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java index 59a403b..3344fd9 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java @@ -1,8 +1,10 @@ package com.bonus.canteen.core.supermarket.service.impl; import java.util.List; +import java.util.Objects; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.security.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.bonus.canteen.core.supermarket.mapper.SupermarketInfoMapper; @@ -51,8 +53,19 @@ public class SupermarketInfoServiceImpl implements ISupermarketInfoService { @Override public int insertSupermarketInfo(SupermarketInfo supermarketInfo) { supermarketInfo.setCreateTime(DateUtils.getNowDate()); + supermarketInfo.setCreateBy(SecurityUtils.getUsername()); try { - return supermarketInfoMapper.insertSupermarketInfo(supermarketInfo); + try { + SupermarketInfo checkResult = supermarketInfoMapper.selectSupermarketInfoBySupermarketName(supermarketInfo); + if (Objects.nonNull(checkResult)) { + throw new ServiceException("该区域超市名称已存在"); + } + return supermarketInfoMapper.insertSupermarketInfo(supermarketInfo); + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } + + } catch (Exception e) { throw new ServiceException(e.getMessage()); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketInfoMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketInfoMapper.xml index e49e601..620113c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketInfoMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketInfoMapper.xml @@ -81,6 +81,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{areaId} + + insert into supermarket_info