diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMapper.java index 04b68af..9aa3a76 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMapper.java @@ -18,6 +18,8 @@ public interface BasicStallMapper { */ public BasicStall selectBasicStallByStallId(Long stallId); + public BasicStall selectBasicStallByStallName(BasicStall allocStall); + public int selectBasicStallCountByCanteenIds(Long[] canteenIds); /** diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMealtimeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMealtimeMapper.java index 6a93cd2..ee3aaf2 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMealtimeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/mapper/BasicStallMealtimeMapper.java @@ -2,6 +2,7 @@ package com.bonus.canteen.core.basic.mapper; import java.util.List; import com.bonus.canteen.core.basic.domain.BasicStallMealtime; +import org.apache.ibatis.annotations.Param; /** * 档口餐次配置Mapper接口 @@ -34,6 +35,8 @@ public interface BasicStallMealtimeMapper { */ public int insertBasicStallMealtime(BasicStallMealtime basicStallMealtime); + public int batchInsertBasicStallMealtime(@Param("list") List allocStallMealtimes); + /** * 修改档口餐次配置 * @@ -57,4 +60,6 @@ public interface BasicStallMealtimeMapper { * @return 结果 */ public int deleteBasicStallMealtimeByIds(Long[] ids); + + public int deleteBasicStallMealtimeByStallId(Long stallId); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/service/impl/BasicStallServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/service/impl/BasicStallServiceImpl.java index 4ecd010..0b7c84b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/service/impl/BasicStallServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/basic/service/impl/BasicStallServiceImpl.java @@ -1,16 +1,25 @@ package com.bonus.canteen.core.basic.service.impl; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import com.bonus.canteen.core.basic.domain.BasicStallMealtime; import com.bonus.canteen.core.basic.mapper.BasicStallMealtimeMapper; +import com.bonus.canteen.core.cook.domain.CookRecipe; +import com.bonus.canteen.core.cook.mapper.CookRecipeMapper; +import com.bonus.canteen.core.device.domain.DeviceBind; +import com.bonus.canteen.core.device.mapper.DeviceBindMapper; +import com.bonus.canteen.core.utils.BnsConstants; 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.basic.mapper.BasicStallMapper; import com.bonus.canteen.core.basic.domain.BasicStall; import com.bonus.canteen.core.basic.service.IBasicStallService; +import org.springframework.util.CollectionUtils; /** * 档口信息Service业务层处理 @@ -24,6 +33,10 @@ public class BasicStallServiceImpl implements IBasicStallService { private BasicStallMapper basicStallMapper; @Autowired private BasicStallMealtimeMapper basicStallMealtimeMapper; + @Autowired + private DeviceBindMapper deviceBindMapper; + @Autowired + CookRecipeMapper cookRecipeMapper; /** * 查询档口信息 @@ -61,8 +74,21 @@ public class BasicStallServiceImpl implements IBasicStallService { @Override public int insertBasicStall(BasicStall basicStall) { basicStall.setCreateTime(DateUtils.getNowDate()); + basicStall.setCreateBy(SecurityUtils.getUsername()); + basicStall.setIfReserve(BnsConstants.COMMON_YES); //默认开启预订餐 try { - return basicStallMapper.insertBasicStall(basicStall); + BasicStall checkResult = basicStallMapper.selectBasicStallByStallName(basicStall); + if (Objects.nonNull(checkResult)) { + throw new ServiceException("该食堂档口名称已存在"); + } + int stallCount = basicStallMapper.insertBasicStall(basicStall); + if (stallCount > 0 && !CollectionUtils.isEmpty(basicStall.getBasicStallMealtimeList())) { + basicStallMealtimeMapper.deleteBasicStallMealtimeByStallId(basicStall.getStallId()); + List mealtimes = basicStall.getBasicStallMealtimeList(); + mealtimes.stream().forEach(o -> o.setStallId(basicStall.getStallId())); + basicStallMealtimeMapper.batchInsertBasicStallMealtime(mealtimes); + } + return stallCount; } catch (Exception e) { throw new ServiceException(e.getMessage()); } @@ -77,8 +103,21 @@ public class BasicStallServiceImpl implements IBasicStallService { @Override public int updateBasicStall(BasicStall basicStall) { basicStall.setUpdateTime(DateUtils.getNowDate()); + basicStall.setUpdateBy(SecurityUtils.getUsername()); try { - return basicStallMapper.updateBasicStall(basicStall); + List allStallList = basicStallMapper.selectBasicStallList(new BasicStall()); + List otherStallNameList = allStallList.stream().filter(item -> !item.getStallId().equals(basicStall.getStallId())) + .filter(item -> item.getCanteenId().equals(basicStall.getCanteenId())) + .map(BasicStall::getStallName).collect(Collectors.toList()); + if (otherStallNameList.contains(basicStall.getStallName())) { + throw new ServiceException("该食堂档口名称已存在"); + } + int stallCount = basicStallMapper.updateBasicStall(basicStall); + if (stallCount > 0 && !CollectionUtils.isEmpty(basicStall.getBasicStallMealtimeList())) { + basicStallMealtimeMapper.deleteBasicStallMealtimeByStallId(basicStall.getStallId()); + basicStallMealtimeMapper.batchInsertBasicStallMealtime(basicStall.getBasicStallMealtimeList()); + } + return stallCount; } catch (Exception e) { throw new ServiceException(e.getMessage()); } @@ -92,7 +131,27 @@ public class BasicStallServiceImpl implements IBasicStallService { */ @Override public int deleteBasicStallByStallIds(Long[] stallIds) { - return basicStallMapper.deleteBasicStallByStallIds(stallIds); + int count = 0; + for (int i = 0; i < stallIds.length; i++) { + Long stallId = stallIds[i]; + //判断档口是否含有设备 + DeviceBind deviceBind = new DeviceBind(); + deviceBind.setStallId(stallId); + List deviceBindList = deviceBindMapper.selectDeviceBindList(deviceBind); + if (!CollectionUtils.isEmpty(deviceBindList) && deviceBindList.size() > 0) { + throw new ServiceException("此档口已绑定设备,不能删除"); + } + //判断档口是否含有菜谱 + CookRecipe cookRecipe = new CookRecipe(); + cookRecipe.setStallId(stallId); + List cookRecipeList = cookRecipeMapper.selectCookRecipeList(cookRecipe); + if (!CollectionUtils.isEmpty(cookRecipeList) && cookRecipeList.size() > 0) { + throw new ServiceException("此档口含有菜谱,不能删除"); + } + basicStallMealtimeMapper.deleteBasicStallMealtimeByStallId(stallId); + count += basicStallMapper.deleteBasicStallByStallId(stallId); + } + return count; } /** @@ -103,6 +162,7 @@ public class BasicStallServiceImpl implements IBasicStallService { */ @Override public int deleteBasicStallByStallId(Long stallId) { + basicStallMealtimeMapper.deleteBasicStallMealtimeByStallId(stallId); return basicStallMapper.deleteBasicStallByStallId(stallId); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicStallMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicStallMapper.xml index cee2436..199667b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicStallMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicStallMapper.xml @@ -66,6 +66,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where bs.stall_id = #{stallId} + + - + + + insert into basic_stall_mealtime(stall_id, mealtime_type, mealtime_name, start_time, end_time) + values + + ( + #{item.stallId}, + #{item.mealtimeType}, + #{item.mealtimeName}, + #{item.startTime}, + #{item.endTime} + ) + + + insert into basic_stall_mealtime @@ -93,4 +107,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + + delete from basic_stall_mealtime where stall_id = #{stallId} + \ No newline at end of file