From 41e65e2a01364f3ac0ec3ee6e22514172013aca4 Mon Sep 17 00:00:00 2001 From: jjLv <1981429112@qq.com> Date: Wed, 14 May 2025 13:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A5=E5=85=BB=E3=80=81=E5=8E=9F=E6=96=99?= =?UTF-8?q?=E3=80=81=E8=8F=9C=E5=93=81=E3=80=81=E8=8F=9C=E8=B0=B1=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/menu/mapper/MenuDishesMapper.java | 6 + .../menu/mapper/MenuDishesTypeMapper.java | 2 + .../mapper/MenuMaterialCategoryMapper.java | 2 + .../core/menu/mapper/MenuMaterialMapper.java | 3 + .../core/menu/mapper/MenuNutritionMapper.java | 2 + .../menu/mapper/MenuNutritionTypeMapper.java | 1 + .../service/impl/MenuDishesServiceImpl.java | 329 ++++++++++-------- .../impl/MenuDishesTypeServiceImpl.java | 6 +- .../impl/MenuMaterialCategoryServiceImpl.java | 8 + .../service/impl/MenuMaterialServiceImpl.java | 14 + .../impl/MenuNutritionServiceImpl.java | 12 + .../impl/MenuNutritionTypeServiceImpl.java | 8 + .../mapper/menu/MenuDishesMapper.xml | 26 +- .../mapper/menu/MenuDishesTypeMapper.xml | 5 +- .../menu/MenuMaterialCategoryMapper.xml | 3 + .../mapper/menu/MenuMaterialMapper.xml | 10 + .../mapper/menu/MenuNutritionMapper.xml | 5 + .../mapper/menu/MenuNutritionTypeMapper.xml | 3 + 18 files changed, 296 insertions(+), 149 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesMapper.java index 9d0b8f8..f93e89f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesMapper.java @@ -97,4 +97,10 @@ public interface MenuDishesMapper extends BaseMapper { List getDishesType(MapBean mapBean); List getDishesTypeByList(@Param("key")String key,@Param("keyList")List keyList); + + List getDishesIds(@Param("ids") Long[] ids); + + List getDetailsIds(@Param("dishesIds") List dishesIds); + + int checkIsExistRelation(@Param("ids") List detailsIds,@Param("type") int i,@Param("nowDate") String nowDate); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesTypeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesTypeMapper.java index 7add354..2ebfd70 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesTypeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuDishesTypeMapper.java @@ -27,4 +27,6 @@ public interface MenuDishesTypeMapper extends BaseMapper { int updateMenuDishesType(MenuDishesTypeEditDTO content); int delMenuDishesType(MenuDishesTypeEditDTO content); + + int checkIsExistRelation(Long typeId); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuMaterialCategoryMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuMaterialCategoryMapper.java index ad89e9f..d46463b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuMaterialCategoryMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuMaterialCategoryMapper.java @@ -74,4 +74,6 @@ public interface MenuMaterialCategoryMapper extends BaseMapper selectMaterialIds(Integer[] ids); + + int checkIsExistRelation(Long id); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionMapper.java index 8327255..7b45ab6 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionMapper.java @@ -71,4 +71,6 @@ public interface MenuNutritionMapper { MenuNutrition getOneByCode(MenuNutrition menuNutrition); MenuNutrition getOneByName(MenuNutrition menuNutrition); + + int checkIsExistRelation(String id); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionTypeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionTypeMapper.java index 542e8f3..9effbae 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionTypeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuNutritionTypeMapper.java @@ -70,4 +70,5 @@ public interface MenuNutritionTypeMapper { MenuNutritionType getParentOne(MenuNutritionType menuNutritionType); + int checkIsExistRelation(Integer id); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesServiceImpl.java index c47f8e0..d5b60bf 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesServiceImpl.java @@ -4,6 +4,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -71,7 +72,7 @@ import javax.validation.constraints.Size; * @date 2025-04-03 */ @Service -public class MenuDishesServiceImpl extends ServiceImpl implements IMenuDishesService { +public class MenuDishesServiceImpl extends ServiceImpl implements IMenuDishesService { @Resource private MenuDishesMapper menuDishesMapper; @@ -161,69 +162,96 @@ public class MenuDishesServiceImpl extends ServiceImpl materialList= menuDishesDTO.getMaterialList(); - List nutritionEntityList = new ArrayList<>(); - System.err.println("长度:"+materialList.size()); - for (MenuDishesAddMaterialDTO i: materialList) { - NutritionEntity nutritionEntity = menuDishesMapper.getNutritionEntity(i); - if(nutritionEntity !=null){ - System.err.println(i.getMaterialId()+",开始值:"+nutritionEntity.getCalcium()); - nutritionEntity.setWeight(i.getWeight()); - nutritionEntity.setBaseWeight(100.0); - nutritionEntityList.add(nutritionEntity); - } - } - if(materialList !=null && materialList.size() > 0){ - menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); - menuDishesMapper.addMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId()),materialList); - } - NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList); - if(nutritionEntityList !=null && nutritionEntityList.size() >0){ - System.err.println("总和:"+nutritionEntity.getCalcium()); - //计算营养成分 - nutritionEntity = countNum(nutritionEntity,menuDishesDTO.getWeight()); - System.err.println("计算后:"+nutritionEntity.getCalcium()); - return menuDishesMapper.addFinalNutrition(nutritionEntity,Long.parseLong(menuDishesDTO.getDishesId())); - }else{ - resetBeanToZero(nutritionEntity); - menuDishesMapper.addFinalNutrition(nutritionEntity,Long.parseLong(menuDishesDTO.getDishesId())); + int baseNum = menuDishesMapper.updateMenuDishesBase(menuDishesDTO); + if (menuDishesDTO.getAreaId() == null) { + menuDishesDTO.setAreaId(-1L); + } + if (menuDishesDTO.getCanteenId() == null) { + menuDishesDTO.setCanteenId(-1L); + } + if (menuDishesDTO.getShopstallId() == null) { + menuDishesDTO.setShopstallId(-1L); + } + if (ObjectUtil.isEmpty(menuDishesDTO.getTypeId())) { + menuDishesDTO.setTypeId(-1L); + } + if (menuDishesDTO.getClassifyId() == null) { + menuDishesDTO.setClassifyId(-1); + } + if (menuDishesDTO.getEffectId() == null) { + menuDishesDTO.setEffectId(-1); + } + if (menuDishesDTO.getStyleId() == null) { + menuDishesDTO.setStyleId(-1); + } + if (menuDishesDTO.getCookId() == null) { + menuDishesDTO.setCookId(-1); + } + if (menuDishesDTO.getSeason() == null) { + menuDishesDTO.setSeason(new ArrayList<>()); + } + if (menuDishesDTO.getSuitIdList() == null) { + menuDishesDTO.setSuitIdList(new ArrayList<>()); + } + if (menuDishesDTO.getTasteIdList() == null) { + menuDishesDTO.setTasteIdList(new ArrayList<>()); + } + if (menuDishesDTO.getLabelIdList() == null) { + menuDishesDTO.setLabelIdList(new ArrayList<>()); + } + addIds(menuDishesDTO); + int dishesNum = menuDishesMapper.editMenuDishes(menuDishesDTO); + List materialList = menuDishesDTO.getMaterialList(); + List nutritionEntityList = new ArrayList<>(); + System.err.println("长度:" + materialList.size()); + for (MenuDishesAddMaterialDTO i : materialList) { + NutritionEntity nutritionEntity = menuDishesMapper.getNutritionEntity(i); + if (nutritionEntity != null) { + System.err.println(i.getMaterialId() + ",开始值:" + nutritionEntity.getCalcium()); + nutritionEntity.setWeight(i.getWeight()); + nutritionEntity.setBaseWeight(100.0); + nutritionEntityList.add(nutritionEntity); } + } + if (materialList != null && materialList.size() > 0) { + menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); + menuDishesMapper.addMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId()), materialList); + } + NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList); + if (nutritionEntityList != null && nutritionEntityList.size() > 0) { + System.err.println("总和:" + nutritionEntity.getCalcium()); + //计算营养成分 + nutritionEntity = countNum(nutritionEntity, menuDishesDTO.getWeight()); + System.err.println("计算后:" + nutritionEntity.getCalcium()); + return menuDishesMapper.addFinalNutrition(nutritionEntity, Long.parseLong(menuDishesDTO.getDishesId())); + } - //添加菜品和材料关系表 - if(materialList != null && materialList.size() > 0){ - menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); - menuDishesMapper.addMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId()),materialList); - }else{ - menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); - } - return menuDishesMapper.editMenuDishes(menuDishesDTO); + //添加菜品和材料关系表 + if (materialList != null && materialList.size() > 0) { + menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); + menuDishesMapper.addMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId()), materialList); + } else { + menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); + } + return menuDishesMapper.editMenuDishes(menuDishesDTO); // } catch (Exception e) { // throw new ServiceException(e.toString()); // } @@ -265,8 +293,23 @@ public class MenuDishesServiceImpl extends ServiceImpl dishesIds = menuDishesMapper.getDishesIds(ids); + //查询detailsId + List detailsIds = menuDishesMapper.getDetailsIds(dishesIds); + //查询是否存在关联关系 + if (detailsIds != null && !detailsIds.isEmpty()){ + int code = menuDishesMapper.checkIsExistRelation(detailsIds,1,null); + if (code > 0) { + throw new ServiceException("存在关联关系,无法删除!"); + } + code = menuDishesMapper.checkIsExistRelation(detailsIds,2, DateUtils.getDate()); + if (code > 0) { + throw new ServiceException("存在关联关系,无法删除!"); + } + } List baseDishesIds = menuDishesMapper.getBassIdByIds(ids); - if(baseDishesIds != null && baseDishesIds.size() >0){ + if (baseDishesIds != null && baseDishesIds.size() > 0) { menuDishesMapper.deleteBaseDishesByIds(baseDishesIds.toArray(new Long[baseDishesIds.size()])); } @@ -295,103 +338,105 @@ public class MenuDishesServiceImpl extends ServiceImpl materialList= menuDishesDTO.getMaterialList(); + List materialList = menuDishesDTO.getMaterialList(); List nutritionEntityList = new ArrayList<>(); - System.err.println("长度:"+materialList.size()); - for (MenuDishesAddMaterialDTO i: materialList) { + System.err.println("长度:" + materialList.size()); + for (MenuDishesAddMaterialDTO i : materialList) { NutritionEntity nutritionEntity = menuDishesMapper.getNutritionEntity(i); - if(nutritionEntity !=null){ - System.err.println(i.getMaterialId()+",开始值:"+nutritionEntity.getCalcium()); + if (nutritionEntity != null) { + System.err.println(i.getMaterialId() + ",开始值:" + nutritionEntity.getCalcium()); nutritionEntity.setWeight(i.getWeight()); nutritionEntity.setBaseWeight(100.0); nutritionEntityList.add(nutritionEntity); } } - if(materialList != null && materialList.size() > 0){ + if (materialList != null && materialList.size() > 0) { //添加菜品和材料关系表 menuDishesMapper.updateMenuMaterialDishes(Long.parseLong(menuDishesDTO.getDishesId())); - menuDishesMapper.addMenuMaterialDishes(dishesId,materialList); + menuDishesMapper.addMenuMaterialDishes(dishesId, materialList); NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList); - if(nutritionEntityList !=null && nutritionEntityList.size() >0){ - System.err.println("总和:"+nutritionEntity.getCalcium()); + if (nutritionEntityList != null && nutritionEntityList.size() > 0) { + System.err.println("总和:" + nutritionEntity.getCalcium()); //计算营养成分 - nutritionEntity = countNum(nutritionEntity,menuDishesDTO.getWeight()); - System.err.println("计算后:"+nutritionEntity.getCalcium()); - return menuDishesMapper.addFinalNutrition(nutritionEntity,dishesId); + nutritionEntity = countNum(nutritionEntity, menuDishesDTO.getWeight()); + System.err.println("计算后:" + nutritionEntity.getCalcium()); + return menuDishesMapper.addFinalNutrition(nutritionEntity, dishesId); } } return 1; } - private void addIds(MenuDishesDTO menuDishesDTO){ + private void addIds(MenuDishesDTO menuDishesDTO) { List labelIdList = menuDishesDTO.getLabelIdList(); List tasteIdList = menuDishesDTO.getTasteIdList(); - List season = menuDishesDTO.getSeason(); + List season = menuDishesDTO.getSeason(); List suitIdList = menuDishesDTO.getSuitIdList(); - List mealList = menuDishesDTO.getMealList(); + List mealList = menuDishesDTO.getMealList(); - if(labelIdList !=null && !labelIdList.isEmpty()){ - String result = labelIdList.stream() .map(String::valueOf).collect(Collectors.joining(",")); + if (labelIdList != null && !labelIdList.isEmpty()) { + String result = labelIdList.stream().map(String::valueOf).collect(Collectors.joining(",")); menuDishesDTO.setLabelId(result); } - if(tasteIdList !=null && !tasteIdList.isEmpty()){ - String result = tasteIdList.stream() .map(String::valueOf).collect(Collectors.joining(",")); + if (tasteIdList != null && !tasteIdList.isEmpty()) { + String result = tasteIdList.stream().map(String::valueOf).collect(Collectors.joining(",")); menuDishesDTO.setTasteId(result); } - if(season !=null && !season.isEmpty()){ - String result = season.stream() .map(String::valueOf).collect(Collectors.joining(",")); + if (season != null && !season.isEmpty()) { + String result = season.stream().map(String::valueOf).collect(Collectors.joining(",")); menuDishesDTO.setSeasonId(result); } - if(suitIdList !=null && !suitIdList.isEmpty()){ - String result = suitIdList.stream() .map(String::valueOf).collect(Collectors.joining(",")); + if (suitIdList != null && !suitIdList.isEmpty()) { + String result = suitIdList.stream().map(String::valueOf).collect(Collectors.joining(",")); menuDishesDTO.setSuitId(result); } - if(mealList !=null && !mealList.isEmpty()){ - String result = mealList.stream() .map(String::valueOf).collect(Collectors.joining(",")); + if (mealList != null && !mealList.isEmpty()) { + String result = mealList.stream().map(String::valueOf).collect(Collectors.joining(",")); menuDishesDTO.setMealId(result); } } - private NutritionEntity countNum(NutritionEntity nutritionEntity,Double weight) { + private NutritionEntity countNum(NutritionEntity nutritionEntity, Double weight) { Field[] fields = nutritionEntity.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); try { Double value = (Double) field.get(nutritionEntity); - if(value !=null){ - System.err.println("先前值----:"+value); - double proportion = Arith.div(weight , 100); + if (value != null) { + System.err.println("先前值----:" + value); + double proportion = Arith.div(weight, 100); value = Arith.mul(value, proportion); field.set(nutritionEntity, value); - System.err.println("后来值++++:"+value); - }else{ + System.err.println("后来值++++:" + value); + } else { field.set(nutritionEntity, 0.00); } @@ -403,16 +448,15 @@ public class MenuDishesServiceImpl extends ServiceImpl menuDishesAddMaterialDTO= menuDishesMapper.getMenuMaterialDishes(menuDishesDTO.getDishesId()); - if(menuDishesAddMaterialDTO !=null){ + List menuDishesAddMaterialDTO = menuDishesMapper.getMenuMaterialDishes(menuDishesDTO.getDishesId()); + if (menuDishesAddMaterialDTO != null) { menuDishesDTO1.setMaterialList(menuDishesAddMaterialDTO); } - List mealList = new ArrayList<>(); - if (menuDishesDTO1.getLabelId() !=null && !menuDishesDTO1.getLabelId().isEmpty()){ + List mealList = new ArrayList<>(); + if (menuDishesDTO1.getLabelId() != null && !menuDishesDTO1.getLabelId().isEmpty()) { List list = Arrays.stream(menuDishesDTO1.getLabelId().split("\\s*,\\s*")) .map(Integer::parseInt) .collect(Collectors.toList()); menuDishesDTO1.setLabelIdList(list); } - if (menuDishesDTO1.getTasteId()!=null && !menuDishesDTO1.getTasteId().isEmpty()){ + if (menuDishesDTO1.getTasteId() != null && !menuDishesDTO1.getTasteId().isEmpty()) { List list = Arrays.stream(menuDishesDTO1.getTasteId().split("\\s*,\\s*")) .map(Integer::parseInt) .collect(Collectors.toList()); menuDishesDTO1.setTasteIdList(list); } - if (menuDishesDTO1.getSeasonId() !=null && !menuDishesDTO1.getSeasonId().isEmpty()){ + if (menuDishesDTO1.getSeasonId() != null && !menuDishesDTO1.getSeasonId().isEmpty()) { List list = Arrays.stream(menuDishesDTO1.getSeasonId().split("\\s*,\\s*")) .map(Integer::parseInt) .collect(Collectors.toList()); menuDishesDTO1.setSeason(list); } - if(menuDishesDTO1.getSuitId() !=null && !menuDishesDTO1.getSuitId().isEmpty()){ + if (menuDishesDTO1.getSuitId() != null && !menuDishesDTO1.getSuitId().isEmpty()) { List list = Arrays.stream(menuDishesDTO1.getSuitId().split("\\s*,\\s*")) .map(Integer::parseInt) .collect(Collectors.toList()); menuDishesDTO1.setSuitIdList(list); } - if(menuDishesDTO1.getMealId() !=null && !menuDishesDTO1.getMealId().isEmpty()){ + if (menuDishesDTO1.getMealId() != null && !menuDishesDTO1.getMealId().isEmpty()) { List list = Arrays.stream(menuDishesDTO1.getMealId().split("\\s*,\\s*")) .map(Integer::parseInt) .collect(Collectors.toList()); menuDishesDTO1.setMealList(list); } - if(-1 == menuDishesDTO1.getCookId()){ + if (-1 == menuDishesDTO1.getCookId()) { menuDishesDTO1.setCookId(null); } - if(menuDishesDTO1.getAreaId()== -1L){ + if (menuDishesDTO1.getAreaId() == -1L) { menuDishesDTO1.setAreaId(null); } - if(menuDishesDTO1.getCanteenId() == -1L){ + if (menuDishesDTO1.getCanteenId() == -1L) { menuDishesDTO1.setCanteenId(null); } - if(menuDishesDTO1.getShopstallId() == -1L){ + if (menuDishesDTO1.getShopstallId() == -1L) { menuDishesDTO1.setShopstallId(null); } return menuDishesDTO1; @@ -488,7 +532,7 @@ public class MenuDishesServiceImpl extends ServiceImpl errorList = new ArrayList<>(); Iterator var19 = menuDishesImportDTOS.iterator(); - while(var19.hasNext()) { - MenuDishesImportDTO data = (MenuDishesImportDTO)var19.next(); + while (var19.hasNext()) { + MenuDishesImportDTO data = (MenuDishesImportDTO) var19.next(); try { BigDecimal price = data.getPrice(); @@ -566,7 +610,7 @@ public class MenuDishesServiceImpl extends ServiceImpl importDishesList, String username) { DishesImportCheckResult dishesImportCheckResult = new DishesImportCheckResult(); List successList = new ArrayList<>(); @@ -726,8 +769,8 @@ public class MenuDishesServiceImpl extends ServiceImpl dishesSizeList = Lists.newArrayList(); Iterator var11 = importDishesList.iterator(); - while(var11.hasNext()) { - MenuDishesImportDTO importDishes = (MenuDishesImportDTO)var11.next(); + while (var11.hasNext()) { + MenuDishesImportDTO importDishes = (MenuDishesImportDTO) var11.next(); try { String sizeTypeStr; @@ -784,7 +827,6 @@ public class MenuDishesServiceImpl extends ServiceImpl result = new ArrayList<>(); Iterator var7 = menuMaterialDishes.iterator(); - while(var7.hasNext()) { - MenuMaterialDishes menuMaterialDish = (MenuMaterialDishes)var7.next(); + while (var7.hasNext()) { + MenuMaterialDishes menuMaterialDish = (MenuMaterialDishes) var7.next(); MenuMaterialNutrition menuMaterialNutrition = data.get(menuMaterialDish.getMaterialId()); if (ObjectUtils.isNotEmpty(menuMaterialNutrition)) { NutritionEntity nutritionEntity = BeanUtil.copyProperties(menuMaterialNutrition, NutritionEntity.class, new String[0]); @@ -919,7 +961,6 @@ public class MenuDishesServiceImpl extends ServiceImpl getMenuMaterialNutrition(List materialIdList) { List menuMaterialNutritions = this.menuMaterialNutritionMapper .selectList(Wrappers.lambdaQuery(MenuMaterialNutrition.class) @@ -968,13 +1009,11 @@ public class MenuDishesServiceImpl extends ServiceImpl canteenMap = importDishesContext.getCanteenMap(); Map allocAreaMap = importDishesContext.getAllocAreaMap(); if (ObjectUtil.isNotEmpty(importDishes.getStallName())) { - stallId = (Long)stallMap.get(importDishes.getStallName()); - canteenId = (Long)canteenStallMap.get(stallId); - areaId = (Long)areaCanteenMap.get(canteenId); + stallId = (Long) stallMap.get(importDishes.getStallName()); + canteenId = (Long) canteenStallMap.get(stallId); + areaId = (Long) areaCanteenMap.get(canteenId); } else if (ObjectUtil.isNotEmpty(importDishes.getCanteenName())) { - canteenId = (Long)canteenMap.get(importDishes.getCanteenName()); - areaId = (Long)areaCanteenMap.get(canteenId); + canteenId = (Long) canteenMap.get(importDishes.getCanteenName()); + areaId = (Long) areaCanteenMap.get(canteenId); } else if (ObjectUtil.isNotEmpty(importDishes.getAreaName())) { - areaId = ((AllocArea)allocAreaMap.get(importDishes.getAreaName())).getAreaId(); + areaId = ((AllocArea) allocAreaMap.get(importDishes.getAreaName())).getAreaId(); } dishesAdd.setCanteenId(canteenId); @@ -1008,7 +1047,7 @@ public class MenuDishesServiceImpl extends ServiceImpl typeMapList = this.menuRecipeMapper.getMenuMaterialTypeMap(); - Map typeMap = new HashMap<>(); + List typeMapList = this.menuRecipeMapper.getMenuMaterialTypeMap(); + Map typeMap = new HashMap<>(); typeMapList.forEach(map -> { typeMap.put(map.getKey(), toLong(map.getValue())); }); List dishesCookMList = this.menuRecipeMapper.getDishesCookMap(); - Map dishesCookMap = new HashMap<>(); + Map dishesCookMap = new HashMap<>(); dishesCookMList.forEach(map -> { dishesCookMap.put(map.getKey(), toLong(map.getValue())); }); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesTypeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesTypeServiceImpl.java index a85f879..f1b450f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesTypeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuDishesTypeServiceImpl.java @@ -59,6 +59,7 @@ public class MenuDishesTypeServiceImpl extends ServiceImpl 0){ + throw new ServiceException("该菜品类型下有数据,不能删除"); + } return menuDishesTypeMapper.delMenuDishesType(content); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialCategoryServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialCategoryServiceImpl.java index 14e82f9..928f13c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialCategoryServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialCategoryServiceImpl.java @@ -259,11 +259,19 @@ public class MenuMaterialCategoryServiceImpl extends ServiceImpl 0){ + throw new ServiceException("存在关联关系,无法删除!"); + } + } menuMaterialCategoryMapper.deleteMenuMaterialCategoryByIds(ids); List childCategoryIds = menuMaterialCategoryMapper.getChildCategoryIds(ids); if(childCategoryIds !=null && childCategoryIds.size() > 0){ String[] idss = childCategoryIds.toArray(new String[childCategoryIds.size()]); // 避免数组扩容 //递归删除 + deleteMenuMaterialCategoryByIds(idss); } return 1; diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialServiceImpl.java index ae4c672..cfcfe01 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuMaterialServiceImpl.java @@ -3,6 +3,7 @@ package com.bonus.canteen.core.menu.service.impl; import java.util.List; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.bonus.canteen.core.menu.domain.MenuMaterialNutrition; @@ -122,6 +123,9 @@ public class MenuMaterialServiceImpl implements IMenuMaterialService { // menuMaterialNutrition.setCategoryId(menuMaterial.getCategoryId()); // this.menuMaterialNutritionMapper.update(menuMaterialNutrition,Wrappers.lambdaUpdate(MenuMaterialNutrition.class).eq(MenuMaterialNutrition::getMaterialId,menuMaterial.getMaterialId()).eq(MenuMaterialNutrition::getCategoryId, menuMaterial.getCategoryId())); // } + if (ObjectUtil.isEmpty(menuMaterial.getNutritionType())){ + menuMaterial.setNutritionType(""); + } return menuMaterialMapper.updateMenuMaterial(menuMaterial); } catch (Exception e) { throw new ServiceException(e.getMessage()); @@ -136,6 +140,16 @@ public class MenuMaterialServiceImpl implements IMenuMaterialService { */ @Override public int deleteMenuMaterialByIds(Integer[] ids) { + //查询materialId + List materialIdList = menuMaterialMapper.selectMaterialIds(ids); + // 判断是否关联了菜品 + for (Long id : materialIdList){ + // 判断是否关联了菜品 + int count = menuMaterialMapper.checkIsExistRelation(id); + if(count > 0){ + throw new ServiceException("存在关联关系,无法删除!"); + } + } return menuMaterialMapper.deleteMenuMaterialByIds(ids); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionServiceImpl.java index ea462de..9003acb 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionServiceImpl.java @@ -122,6 +122,13 @@ public class MenuNutritionServiceImpl implements IMenuNutritionService { */ @Override public int deleteMenuNutritionByIds(String[] ids) { + for (String id : ids){ + // 判断是否关联了菜品 + int count = menuNutritionMapper.checkIsExistRelation(id); + if(count > 0){ + throw new ServiceException("存在关联关系,无法删除!"); + } + } return menuNutritionMapper.deleteMenuNutritionByIds(ids); } @@ -133,6 +140,11 @@ public class MenuNutritionServiceImpl implements IMenuNutritionService { */ @Override public int deleteMenuNutritionById(Long id) { + // 判断是否关联了菜品 + int count = menuNutritionMapper.checkIsExistRelation(String.valueOf(id)); + if(count > 0){ + throw new ServiceException("存在关联关系,无法删除!"); + } return menuNutritionMapper.deleteMenuNutritionById(id); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionTypeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionTypeServiceImpl.java index 5e7982d..37550a1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionTypeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuNutritionTypeServiceImpl.java @@ -115,6 +115,14 @@ public class MenuNutritionTypeServiceImpl implements IMenuNutritionTypeService { if(ids == null || ids.length == 0){ throw new ServiceException("请选择要删除的营养基础类型"); } + for (int i = 0; i < ids.length; i++) { + int code = menuNutritionTypeMapper.checkIsExistRelation(ids[i]); + if(code > 0){ + throw new ServiceException("该营养基础类型下有数据,不能删除"); + } + + } + return menuNutritionTypeMapper.deleteMenuNutritionTypeByIds(ids); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesMapper.xml index bcebcb4..28284e7 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesMapper.xml @@ -99,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from menu_dishes_base where base_dishes_id in + update menu_dishes_base set del_flag = '2'where base_dishes_id in #{item} @@ -581,9 +582,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item} + + + - delete from menu_dishes where id in + update menu_dishes set del_flag = '2' where id in #{item} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesTypeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesTypeMapper.xml index d67232b..a383dcf 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesTypeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuDishesTypeMapper.xml @@ -47,8 +47,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by du.id desc + - + update menu_dishes_type set type_name = #{typeName} where type_id = #{typeId} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialCategoryMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialCategoryMapper.xml index 34f061a..c67c317 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialCategoryMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialCategoryMapper.xml @@ -131,6 +131,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialMapper.xml index 685676e..e5c780c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuMaterialMapper.xml @@ -227,6 +227,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where mm.material_id = #{id} + + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionMapper.xml index 2c2996b..21c2e4a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionMapper.xml @@ -491,5 +491,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" limit 1 + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionTypeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionTypeMapper.xml index 7a6016c..468d14f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionTypeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuNutritionTypeMapper.xml @@ -106,6 +106,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +