菜谱管理

This commit is contained in:
sxu 2025-06-01 06:20:04 +08:00
parent 070bf9c495
commit 988d3bb4a6
2 changed files with 37 additions and 40 deletions

View File

@ -82,7 +82,8 @@ public interface CookRecipeMapper {
int insertBind(CookAppRecipe appRecipe);
void updateRecipeByCanteenStallMeal(@Param("recipeId")String recipeId, @Param("canteenId")String canteenId, @Param("stallId")String stallId, @Param("deviceIds")List<Integer> deviceIds);
void updateRecipeByCanteenStallMeal(@Param("recipeId")Long recipeId, @Param("canteenId")Long canteenId,
@Param("stallId")Long stallId, @Param("deviceIds")List<Integer> deviceIds);
/**
* 删除菜品计划信息

View File

@ -15,6 +15,7 @@ import com.bonus.canteen.core.cook.domain.CookAppRecipe;
import com.bonus.canteen.core.cook.domain.CookRecipeDetail;
import com.bonus.canteen.core.cook.domain.CookRecipeDishes;
import com.bonus.canteen.core.cook.dto.*;
import com.bonus.canteen.core.cook.enums.CookBindTypeEnum;
import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum;
import com.bonus.canteen.core.cook.enums.RecipeDetailTypeEnum;
import com.bonus.canteen.core.cook.enums.RecipeTypeEnum;
@ -363,65 +364,60 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
}
}
public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO) {
CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId());
List<Integer> deviceInfoList = new ArrayList<>();
List<String> deviceSnList = 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("该食堂档口下没有设备信息");
}
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<Integer> deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId()));
@Transactional(rollbackFor = {Exception.class})
public void bindCookRecipe(CookRecipeBindDTO content) {
CookRecipe cookRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(content.getRecipeId());
CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(content.getBindType());
CookAppRecipe appRecipe = new CookAppRecipe();
if (ObjectUtil.isEmpty(sortEnum)) {
throw new ServiceException("bingType值异常");
throw new ServiceException("菜谱绑定类型错误");
} else {
List<Integer> deviceTypes = sortEnum.getDeviceType();
if (cookRecipeDTO.getHandleType().equals(1)) {
if (content.getHandleType().equals(1)) {
boolean exists;
// if (CookBindTypeEnum.RESERVE.key().equals(cookRecipeDTO.getBindType())) {
// exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId());
// if (CookBindTypeEnum.RESERVE.key().equals(content.getBindType())) {
// exists = this.allocCanteenApi.checkCanteenIfReserve(cookRecipe.getCanteenId(), cookRecipe.getStallId());
// if (!exists) {
// throw new ServiceException("不支持预订餐");
// }
// }
exists = this.cookRecipeMapper.checkIfAlreadyBind(mar);
appRecipe.setRecipeId(content.getRecipeId());
appRecipe.setMealLineId(content.getMealLineId());
appRecipe.setBindType(content.getBindType());
appRecipe.setBindTime(LocalDateTime.now());
exists = this.cookRecipeMapper.checkIfAlreadyBind(appRecipe);
if (exists) {
throw new ServiceException("菜谱已被使用,请勿重复绑定");
}
List<Long> sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), cookRecipeDTO.getBindType(), cookRecipeDTO.getMealLineId());
List<Long> sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(cookRecipe.getStallId(), content.getBindType(), content.getMealLineId());
if (ObjectUtil.isNotEmpty(sourceRecipeList)) {
mar.setRecipeIds(sourceRecipeList);
this.cookRecipeMapper.deleteBind(mar);
appRecipe.setRecipeIds(sourceRecipeList);
this.cookRecipeMapper.deleteBind(appRecipe);
}
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);
if (ObjectUtil.isNotEmpty(deviceTypes)) {
this.cookRecipeMapper.updateRecipeByCanteenStallMeal(content.getRecipeId(), cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceTypes);
}
MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
MqUtil.sendDataChange(cookRecipe, 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);
appRecipe.setRecipeIds(Collections.singletonList(appRecipe.getRecipeId()));
this.cookRecipeMapper.deleteBind(appRecipe);
if (ObjectUtil.isNotEmpty(deviceTypes)) {
this.cookRecipeMapper.updateRecipeByCanteenStallMeal(-1L, cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceTypes);
}
}
//发送mq
if (!CollectionUtils.isEmpty(deviceSnList)) {
if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机")
List<Integer> deviceInfoList = new ArrayList<>();
if (content.getStallId() != null) {
deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(content.getStallId()));
if (deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0) {
throw new ServiceException("该食堂档口下没有设备信息");
}
}
List<String> deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
for (String deviceSn : deviceSnList) {
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, cookRecipeDTO.getHandleType().equals(1) ? "update" : "del");
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, content.getHandleType().equals(1) ? "update" : "del");
MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
}
}