From d9bfcc0c307b79c8592ab4e572daf9bedca5eb12 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Thu, 29 May 2025 13:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=8F=9C=E8=B0=B1bind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/cook/mapper/CookRecipeMapper.java | 16 +++ .../service/impl/CookRecipeServiceImpl.java | 106 +++++++++--------- .../mapper/cook/CookRecipeMapper.xml | 61 ++++++++++ 3 files changed, 130 insertions(+), 53 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java index 521a650..785e532 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java @@ -2,6 +2,8 @@ package com.bonus.canteen.core.cook.mapper; import java.time.LocalDate; import java.util.List; + +import com.bonus.canteen.core.cook.domain.CookAppRecipe; import com.bonus.canteen.core.cook.domain.CookRecipe; import com.bonus.canteen.core.cook.dto.CookRecipeDTO; import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO; @@ -59,6 +61,20 @@ public interface CookRecipeMapper { */ public int updateCookRecipe(CookRecipeDTO cookRecipeDTO); + List getDeviceIdByDevivce(@Param("canteenId")String canteenId, @Param("stallId")String stallId); + + List getDeviceSnByIds(@Param("list") List deviceInfoList); + + boolean checkIfAlreadyBind(CookAppRecipe appRecipe); + + List selectRecipeInSameShop(@Param("stallId") Long stallId, @Param("bindType") Integer bindType, @Param("mealLineId") Long mealLineId); + + void deleteBind(CookAppRecipe appRecipe); + + int insertBind(CookAppRecipe appRecipe); + + void updateRecipeByCanteenStallMeal(@Param("recipeId")String recipeId, @Param("canteenId")String canteenId, @Param("stallId")String stallId, @Param("deviceIds")List deviceIds); + /** * 删除菜品计划信息 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index 8b721ae..734ea84 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -308,65 +308,65 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO) { -// CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId()); -// List deviceInfoList = new ArrayList<>(); -// if(cookRecipeDTO.getStallId() !=null){ -// deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId())); -// if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){ -// throw new ServiceException("该食堂档口下没有设备信息"); -// } -// } -// List deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList); -// CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType()); -// CookAppRecipe mar = new CookAppRecipe(); -// mar.setRecipeId(cookRecipeDTO.getRecipeId()); -// mar.setMealLineId(cookRecipeDTO.getMealLineId()); -// mar.setBindType(cookRecipeDTO.getBindType()); -// List deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId())); -// if (ObjectUtil.isEmpty(sortEnum)) { -// throw new ServiceException("bingType值异常"); -// } else { -// List deviceTypes = sortEnum.getDeviceType(); -// if (cookRecipeDTO.getHandleType().equals(1)) { -// boolean exists; + CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId()); + List deviceInfoList = new ArrayList<>(); + if(cookRecipeDTO.getStallId() !=null){ + deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId())); + if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){ + throw new ServiceException("该食堂档口下没有设备信息"); + } + } + List deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList); + CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType()); + CookAppRecipe mar = new CookAppRecipe(); + mar.setRecipeId(cookRecipeDTO.getRecipeId()); + mar.setMealLineId(cookRecipeDTO.getMealLineId()); + mar.setBindType(cookRecipeDTO.getBindType()); + List deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId())); + if (ObjectUtil.isEmpty(sortEnum)) { + throw new ServiceException("bingType值异常"); + } else { + List deviceTypes = sortEnum.getDeviceType(); + if (cookRecipeDTO.getHandleType().equals(1)) { + boolean exists; // if (CookBindTypeEnum.RESERVE.key().equals(cookRecipeDTO.getBindType())) { // exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId()); // if (!exists) { // throw new ServiceException("不支持预订餐"); // } // } -// exists = this.cookRecipeMapper.exists(mar); -// if (exists) { -// throw new ServiceException("菜谱已被使用,请勿重复绑定"); -// } -// List sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), null, cookRecipeDTO.getBindType(), content.getMealLineId()); -// if (ObjectUtil.isNotEmpty(sourceRecipeList)) { -// mar.setRecipeIds(sourceRecipeList); -// this.cookRecipeMapper.delete(mar); -// } -// CookAppRecipe appRecipe = new CookAppRecipe(); -// appRecipe.setRecipeId(cookRecipeDTO.getRecipeId()); -// appRecipe.setBindType(cookRecipeDTO.getBindType()); -// appRecipe.setMealLineId(cookRecipeDTO.getMealLineId()); -// appRecipe.setBindTime(LocalDateTime.now()); -// this.cookRecipeMapper.insert(appRecipe); -// if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { -// this.cookRecipeMapper.updateRecipeByCanteeStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList); -// } -// MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE); -// } else { -// mar.setRecipeIds(Collections.singletonList(mar.getRecipeId())); -// this.cookRecipeMapper.delete(mar); -// if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { -// this.cookRecipeMapper.updateRecipeByCanteeStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList); -// } -// } -// //发送mq -// for (String deviceSn : deviceSnList){ -// DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,cookRecipeDTO.getHandleType().equals(1) ? "update" : "del"); -// MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn); -// } -// } + exists = this.cookRecipeMapper.checkIfAlreadyBind(mar); + if (exists) { + throw new ServiceException("菜谱已被使用,请勿重复绑定"); + } + List sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), cookRecipeDTO.getBindType(), cookRecipeDTO.getMealLineId()); + if (ObjectUtil.isNotEmpty(sourceRecipeList)) { + mar.setRecipeIds(sourceRecipeList); + this.cookRecipeMapper.deleteBind(mar); + } + CookAppRecipe appRecipe = new CookAppRecipe(); + appRecipe.setRecipeId(cookRecipeDTO.getRecipeId()); + appRecipe.setBindType(cookRecipeDTO.getBindType()); + appRecipe.setMealLineId(cookRecipeDTO.getMealLineId()); + appRecipe.setBindTime(LocalDateTime.now()); + this.cookRecipeMapper.insertBind(appRecipe); + if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { + this.cookRecipeMapper.updateRecipeByCanteenStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList); + } + MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE); + } else { + mar.setRecipeIds(Collections.singletonList(mar.getRecipeId())); + this.cookRecipeMapper.deleteBind(mar); + if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { + this.cookRecipeMapper.updateRecipeByCanteenStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList); + } + } + //发送mq + for (String deviceSn : deviceSnList){ + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,cookRecipeDTO.getHandleType().equals(1) ? "update" : "del"); + MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn); + } + } } /** diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml index 89e6945..7044b08 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml @@ -188,6 +188,67 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where recipe_id = #{recipeId} + + + + + + + + + + delete from cook_recipe_bind_app where recipe_id in + + #{recipeId} + + + and meal_line_id = #{mealLineId} + + and bind_type = #{bindType} + + + + insert into cook_recipe_bind_app (recipe_id,bind_type,bind_time,meal_line_id) + values (#{recipeId},#{bindType},now(),#{mealLineId}) + + + + update cook_recipe_bind_device set recipe_id = #{ recipeId} + where canteen_id = #{canteenId} and stall_id = #{stallId} + and device_id in + + #{item} + + + update cook_recipe set del_flag = '2' where recipe_id = #{recipeId}