diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialMapper.java index 4f9a730..a58789e 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialMapper.java @@ -57,4 +57,6 @@ public interface SupermarketMaterialMapper { * @return 结果 */ public int deleteSupermarketMaterialByMaterialIds(Long[] materialIds); + + public int getSupermarketMaterialCountByMaterialTypes(Long[] materialTypeIds); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialTypeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialTypeMapper.java index 5b2a21d..71c00b9 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialTypeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketMaterialTypeMapper.java @@ -18,6 +18,8 @@ public interface SupermarketMaterialTypeMapper { */ public SupermarketMaterialType selectSupermarketMaterialTypeByMaterialTypeId(Long materialTypeId); + public SupermarketMaterialType selectSupermarketMaterialTypeByMaterialTypeName(SupermarketMaterialType supermarketMaterialType); + /** * 查询商品类别列表 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialTypeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialTypeServiceImpl.java index 39685c5..bfcf42a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialTypeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialTypeServiceImpl.java @@ -1,8 +1,12 @@ package com.bonus.canteen.core.supermarket.service.impl; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import com.bonus.canteen.core.supermarket.mapper.SupermarketMaterialMapper; 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.SupermarketMaterialTypeMapper; @@ -19,6 +23,8 @@ import com.bonus.canteen.core.supermarket.service.ISupermarketMaterialTypeServic public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialTypeService { @Autowired private SupermarketMaterialTypeMapper supermarketMaterialTypeMapper; + @Autowired + private SupermarketMaterialMapper supermarketMaterialMapper; /** * 查询商品类别 @@ -51,7 +57,12 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT @Override public int insertSupermarketMaterialType(SupermarketMaterialType supermarketMaterialType) { supermarketMaterialType.setCreateTime(DateUtils.getNowDate()); + supermarketMaterialType.setCreateBy(SecurityUtils.getUsername()); try { + SupermarketMaterialType checkResult = supermarketMaterialTypeMapper.selectSupermarketMaterialTypeByMaterialTypeName(supermarketMaterialType); + if (Objects.nonNull(checkResult)) { + throw new ServiceException("改超市商品类别名已存在"); + } return supermarketMaterialTypeMapper.insertSupermarketMaterialType(supermarketMaterialType); } catch (Exception e) { throw new ServiceException(e.getMessage()); @@ -67,7 +78,14 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT @Override public int updateSupermarketMaterialType(SupermarketMaterialType supermarketMaterialType) { supermarketMaterialType.setUpdateTime(DateUtils.getNowDate()); + supermarketMaterialType.setUpdateBy(SecurityUtils.getUsername()); try { + List allSupermarketMaterialTypeList = supermarketMaterialTypeMapper.selectSupermarketMaterialTypeList(new SupermarketMaterialType()); + List otherSupermarketMaterialTypeList = allSupermarketMaterialTypeList.stream().filter(item -> !item.getMaterialTypeId().equals(supermarketMaterialType.getMaterialTypeId())) + .map(SupermarketMaterialType::getMaterialTypeName).collect(Collectors.toList()); + if (otherSupermarketMaterialTypeList.contains(supermarketMaterialType.getMaterialTypeName())) { + throw new ServiceException("改超市商品类别名已存在"); + } return supermarketMaterialTypeMapper.updateSupermarketMaterialType(supermarketMaterialType); } catch (Exception e) { throw new ServiceException(e.getMessage()); @@ -82,6 +100,10 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT */ @Override public int deleteSupermarketMaterialTypeByMaterialTypeIds(Long[] materialTypeIds) { + int count = supermarketMaterialMapper.getSupermarketMaterialCountByMaterialTypes(materialTypeIds); + if (count > 0) { + throw new ServiceException("该超市商品类型含有商品信息,不能删除"); + } return supermarketMaterialTypeMapper.deleteSupermarketMaterialTypeByMaterialTypeIds(materialTypeIds); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialMapper.xml index 04c20f5..d78facb 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialMapper.xml @@ -143,4 +143,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{materialId} + + \ No newline at end of file diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialTypeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialTypeMapper.xml index 9d48191..bde6234 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialTypeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketMaterialTypeMapper.xml @@ -16,7 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select material_type_id, material_type_name, parent_id, level, area_id, create_by, create_time, update_by, update_time from supermarket_material_type + select material_type_id, material_type_name, parent_id, level, area_id, create_by, create_time, update_by, update_time + from supermarket_material_type + + insert into supermarket_material_type