菜谱管理

This commit is contained in:
sxu 2025-06-01 06:56:32 +08:00
parent 988d3bb4a6
commit 868b02929e
3 changed files with 28 additions and 29 deletions

View File

@ -70,7 +70,7 @@ public interface CookRecipeMapper {
*/ */
public int updateCookRecipe(CookRecipeDTO cookRecipeDTO); public int updateCookRecipe(CookRecipeDTO cookRecipeDTO);
List<Integer> getDeviceIdByDevivce(@Param("canteenId")String canteenId, @Param("stallId")String stallId); List<Integer> getDeviceIdByDevice(@Param("canteenId")String canteenId, @Param("stallId")String stallId);
List<String> getDeviceSnByIds(@Param("list") List<Integer> deviceInfoList); List<String> getDeviceSnByIds(@Param("list") List<Integer> deviceInfoList);

View File

@ -22,7 +22,6 @@ import com.bonus.canteen.core.cook.enums.RecipeTypeEnum;
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper; import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper; import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
import com.bonus.canteen.core.cook.vo.*; import com.bonus.canteen.core.cook.vo.*;
import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO;
import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.houqin.constant.GlobalConstants; import com.bonus.common.houqin.constant.GlobalConstants;
@ -368,24 +367,31 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
public void bindCookRecipe(CookRecipeBindDTO content) { public void bindCookRecipe(CookRecipeBindDTO content) {
CookRecipe cookRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(content.getRecipeId()); CookRecipe cookRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(content.getRecipeId());
CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(content.getBindType()); CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(content.getBindType());
CookAppRecipe appRecipe = new CookAppRecipe();
if (ObjectUtil.isEmpty(sortEnum)) { if (ObjectUtil.isEmpty(sortEnum)) {
throw new ServiceException("菜谱绑定类型错误"); throw new ServiceException("菜谱绑定类型错误");
} else { } else {
List<Integer> deviceTypes = sortEnum.getDeviceType(); List<Integer> deviceIds = new ArrayList<>();
if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机")
if (content.getStallId() != null) {
deviceIds = this.cookRecipeMapper.getDeviceIdByDevice(null, String.valueOf(content.getStallId()));
if (deviceIds == null || deviceIds.isEmpty() || deviceIds.size() == 0) {
throw new ServiceException("该食堂档口下没有设备信息");
}
}
}
CookAppRecipe appRecipe = new CookAppRecipe();
appRecipe.setRecipeId(content.getRecipeId());
appRecipe.setMealLineId(content.getMealLineId());
appRecipe.setBindType(content.getBindType());
appRecipe.setBindTime(LocalDateTime.now());
if (content.getHandleType().equals(1)) { if (content.getHandleType().equals(1)) {
boolean exists;
// if (CookBindTypeEnum.RESERVE.key().equals(content.getBindType())) { // if (CookBindTypeEnum.RESERVE.key().equals(content.getBindType())) {
// exists = this.allocCanteenApi.checkCanteenIfReserve(cookRecipe.getCanteenId(), cookRecipe.getStallId()); // exists = this.allocCanteenApi.checkCanteenIfReserve(cookRecipe.getCanteenId(), cookRecipe.getStallId());
// if (!exists) { // if (!exists) {
// throw new ServiceException("不支持预订餐"); // throw new ServiceException("不支持预订餐");
// } // }
// } // }
appRecipe.setRecipeId(content.getRecipeId()); boolean exists = this.cookRecipeMapper.checkIfAlreadyBind(appRecipe);
appRecipe.setMealLineId(content.getMealLineId());
appRecipe.setBindType(content.getBindType());
appRecipe.setBindTime(LocalDateTime.now());
exists = this.cookRecipeMapper.checkIfAlreadyBind(appRecipe);
if (exists) { if (exists) {
throw new ServiceException("菜谱已被使用,请勿重复绑定"); throw new ServiceException("菜谱已被使用,请勿重复绑定");
} }
@ -395,32 +401,25 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
this.cookRecipeMapper.deleteBind(appRecipe); this.cookRecipeMapper.deleteBind(appRecipe);
} }
this.cookRecipeMapper.insertBind(appRecipe); this.cookRecipeMapper.insertBind(appRecipe);
if (ObjectUtil.isNotEmpty(deviceTypes)) { if (ObjectUtil.isNotEmpty(deviceIds)) {
this.cookRecipeMapper.updateRecipeByCanteenStallMeal(content.getRecipeId(), cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceTypes); this.cookRecipeMapper.updateRecipeByCanteenStallMeal(content.getRecipeId(), cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceIds);
} }
MqUtil.sendDataChange(cookRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE); MqUtil.sendDataChange(cookRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
} else { } else {
appRecipe.setRecipeIds(Collections.singletonList(appRecipe.getRecipeId())); appRecipe.setRecipeIds(Collections.singletonList(appRecipe.getRecipeId()));
this.cookRecipeMapper.deleteBind(appRecipe); this.cookRecipeMapper.deleteBind(appRecipe);
if (ObjectUtil.isNotEmpty(deviceTypes)) { if (ObjectUtil.isNotEmpty(deviceIds)) {
this.cookRecipeMapper.updateRecipeByCanteenStallMeal(-1L, cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceTypes); this.cookRecipeMapper.updateRecipeByCanteenStallMeal(-1L, cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceIds);
} }
} }
//发送mq //发送mq
if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机") // if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机")
List<Integer> deviceInfoList = new ArrayList<>(); // List<String> deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
if (content.getStallId() != null) { // for (String deviceSn : deviceSnList) {
deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(content.getStallId())); // DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, content.getHandleType().equals(1) ? "update" : "del");
if (deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0) { // MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
throw new ServiceException("该食堂档口下没有设备信息"); // }
} // }
}
List<String> deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
for (String deviceSn : deviceSnList) {
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, content.getHandleType().equals(1) ? "update" : "del");
MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
}
}
} }
} }

View File

@ -294,7 +294,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where recipe_id = #{recipeId} where recipe_id = #{recipeId}
</update> </update>
<select id="getDeviceIdByDevivce" parameterType="string" resultType="integer"> <select id="getDeviceIdByDevice" parameterType="string" resultType="integer">
select a.device_id select a.device_id
from device_info a from device_info a
LEFT JOIN cook_recipe_bind_device b on a.device_id = b.device_id LEFT JOIN cook_recipe_bind_device b on a.device_id = b.device_id