diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesController.java index 79106e3..0d8afeb 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesController.java @@ -41,7 +41,6 @@ public class CookDishesController extends BaseController { * 查询菜品信息列表 */ @ApiOperation(value = "查询菜品信息列表") - //@RequiresPermissions("cook:dishes:list") @GetMapping("/list") public TableDataInfo list(CookDishes cookDishes) { startPage(); @@ -53,8 +52,6 @@ public class CookDishesController extends BaseController { * 导出菜品信息列表 */ @ApiOperation(value = "导出菜品信息列表") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:dishes:export") @SysLog(title = "菜品信息", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出菜品信息") @PostMapping("/export") public void export(HttpServletResponse response, CookDishes cookDishes) { @@ -67,7 +64,6 @@ public class CookDishesController extends BaseController { * 获取菜品信息详细信息 */ @ApiOperation(value = "获取菜品信息详细信息") - //@RequiresPermissions("cook:dishes:query") @GetMapping(value = "/{dishesId}") public AjaxResult getInfo(@PathVariable("dishesId") Long dishesId) { return success(cookDishesService.selectCookDishesByDishesId(dishesId)); @@ -77,10 +73,8 @@ public class CookDishesController extends BaseController { * 新增菜品信息 */ @ApiOperation(value = "新增菜品信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:dishes:add") @SysLog(title = "菜品信息", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增菜品信息") - @PostMapping + @PostMapping("/add") public AjaxResult add(@RequestBody CookDishes cookDishes) { try { return toAjax(cookDishesService.insertCookDishes(cookDishes)); @@ -93,8 +87,6 @@ public class CookDishesController extends BaseController { * 修改菜品信息 */ @ApiOperation(value = "修改菜品信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:dishes:edit") @SysLog(title = "菜品信息", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改菜品信息") @PostMapping("/edit") public AjaxResult edit(@RequestBody CookDishes cookDishes) { @@ -109,8 +101,6 @@ public class CookDishesController extends BaseController { * 删除菜品信息 */ @ApiOperation(value = "删除菜品信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:dishes:remove") @SysLog(title = "菜品信息", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除菜品信息") @PostMapping("/del/{dishesIds}") public AjaxResult remove(@PathVariable Long[] dishesIds) { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesTypeController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesTypeController.java index 0342fcb..c5cbeba 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesTypeController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookDishesTypeController.java @@ -2,6 +2,9 @@ package com.bonus.canteen.core.cook.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import com.bonus.canteen.core.common.utils.TreeNodeUtil; +import com.bonus.canteen.core.cook.vo.CookDishesTypeVO; import com.bonus.common.log.enums.OperaType; //import com.bonus.canteen.core.cook.common.annotation.PreventRepeatSubmit; import io.swagger.annotations.Api; @@ -40,34 +43,18 @@ public class CookDishesTypeController extends BaseController { /** * 查询菜品类型信息列表 */ - @ApiOperation(value = "查询菜品类型信息列表") - //@RequiresPermissions("cook:type:list") + @ApiOperation(value = "获取所有菜品类别") @GetMapping("/list") - public TableDataInfo list(CookDishesType cookDishesType) { - startPage(); - List list = cookDishesTypeService.selectCookDishesTypeList(cookDishesType); - return getDataTable(list); + public AjaxResult list(CookDishesType cookDishesType) { + List list = cookDishesTypeService.selectList(cookDishesType); + return AjaxResult.success(TreeNodeUtil.assembleTree(list)); } - /** - * 导出菜品类型信息列表 - */ - @ApiOperation(value = "导出菜品类型信息列表") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:type:export") - @SysLog(title = "菜品类型信息", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出菜品类型信息") - @PostMapping("/export") - public void export(HttpServletResponse response, CookDishesType cookDishesType) { - List list = cookDishesTypeService.selectCookDishesTypeList(cookDishesType); - ExcelUtil util = new ExcelUtil(CookDishesType.class); - util.exportExcel(response, list, "菜品类型信息数据"); - } /** * 获取菜品类型信息详细信息 */ @ApiOperation(value = "获取菜品类型信息详细信息") - //@RequiresPermissions("cook:type:query") @GetMapping(value = "/{dishesTypeId}") public AjaxResult getInfo(@PathVariable("dishesTypeId") Long dishesTypeId) { return success(cookDishesTypeService.selectCookDishesTypeByDishesTypeId(dishesTypeId)); @@ -77,10 +64,8 @@ public class CookDishesTypeController extends BaseController { * 新增菜品类型信息 */ @ApiOperation(value = "新增菜品类型信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:type:add") @SysLog(title = "菜品类型信息", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增菜品类型信息") - @PostMapping + @PostMapping("/add") public AjaxResult add(@RequestBody CookDishesType cookDishesType) { try { return toAjax(cookDishesTypeService.insertCookDishesType(cookDishesType)); @@ -93,8 +78,6 @@ public class CookDishesTypeController extends BaseController { * 修改菜品类型信息 */ @ApiOperation(value = "修改菜品类型信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:type:edit") @SysLog(title = "菜品类型信息", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改菜品类型信息") @PostMapping("/edit") public AjaxResult edit(@RequestBody CookDishesType cookDishesType) { @@ -109,8 +92,6 @@ public class CookDishesTypeController extends BaseController { * 删除菜品类型信息 */ @ApiOperation(value = "删除菜品类型信息") - //@PreventRepeatSubmit - //@RequiresPermissions("cook:type:remove") @SysLog(title = "菜品类型信息", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除菜品类型信息") @PostMapping("/del/{dishesTypeIds}") public AjaxResult remove(@PathVariable Long[] dishesTypeIds) { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java index 999c7c1..94829d0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java @@ -1,6 +1,8 @@ package com.bonus.canteen.core.cook.domain; import java.math.BigDecimal; +import java.util.List; + import com.bonus.common.core.annotation.Excel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -23,6 +25,8 @@ public class CookDishes extends BaseEntity { /** 菜品id */ private Long dishesId; + private Long baseDishesId; + /** 类型(1-菜品,2-套餐) */ @Excel(name = "类型(1-菜品,2-套餐)") @ApiModelProperty(value = "类型(1-菜品,2-套餐)") @@ -300,7 +304,7 @@ public class CookDishes extends BaseEntity { /** 档口或店铺id */ @Excel(name = "档口或店铺id") @ApiModelProperty(value = "档口或店铺id") - private Long shopstallId; + private Long stallId; /** 隐藏标识(1隐藏,2展示) */ @Excel(name = "隐藏标识(1隐藏,2展示)") @@ -342,5 +346,21 @@ public class CookDishes extends BaseEntity { @ApiModelProperty(value = "餐次id") private String mealId; + @ApiModelProperty(value = "菜品食材列表") + private List dishesMaterialList; + @ApiModelProperty(value = "食堂名称") + private String canteenName; + + @ApiModelProperty(value = "档口名称") + private String stallName; + + @ApiModelProperty(value = "区域名称") + private String areaName; + + @ApiModelProperty(value = "菜品类型名称") + private String dishesTypeName; + + @ApiModelProperty(value = "菜品类型id集合") + private List typeIds; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishesType.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishesType.java index 67a6088..aa494a1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishesType.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishesType.java @@ -3,9 +3,11 @@ package com.bonus.canteen.core.cook.domain; import com.bonus.common.core.annotation.Excel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.ToString; import com.bonus.common.core.web.domain.BaseEntity; + /** * 菜品类型信息对象 cook_dishes_type * @@ -14,6 +16,7 @@ import com.bonus.common.core.web.domain.BaseEntity; */ +@EqualsAndHashCode(callSuper = true) @Data @ToString public class CookDishesType extends BaseEntity { @@ -52,5 +55,4 @@ public class CookDishesType extends BaseEntity { @ApiModelProperty(value = "类别别称") private String dishesAliasName; - } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesMapper.java index ac9424f..6b0b9f0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesMapper.java @@ -2,6 +2,9 @@ package com.bonus.canteen.core.cook.mapper; import java.util.List; import com.bonus.canteen.core.cook.domain.CookDishes; +import com.bonus.canteen.core.cook.domain.CookDishesMaterial; +import com.bonus.canteen.core.utils.NutritionEntity; +import org.apache.ibatis.annotations.Param; /** * 菜品信息Mapper接口 @@ -57,4 +60,68 @@ public interface CookDishesMapper { * @return 结果 */ public int deleteCookDishesByDishesIds(Long[] dishesIds); + + /** + * 校验菜品名称是否唯一 + * + * @param cookDishes 菜品名称 + * @return 结果 + */ + public int checkDishIsExist(CookDishes cookDishes); + + /** + * 新增菜品信息 + * + * @param cookDishes 菜品信息 + * @return 结果 + */ + int insertDishesName(CookDishes cookDishes); + + /** + * 新增菜品信息 + * + * @param dishesMaterialList 菜品信息 + * @param dishesId 菜品id + */ + void insertDishesMaterial(@Param("list") List dishesMaterialList,@Param("dishesId") Long dishesId); + + /** + * 修改菜品信息 + * + * @param cookDishes 菜品信息 + */ + void updateDishesName(CookDishes cookDishes); + + /** + * 删除菜品信息 + * + * @param dishesId 菜品id + */ + void deleteDishesMaterialByDishesId(Long dishesId); + + /** + * 根据菜品id查询菜品营养信息 + * + * @param nutritionEntity 菜品营养信息 + * @param dishesId 菜品id + * @return 菜品营养信息 + */ + int updateFinalNutrition(@Param("bean") NutritionEntity nutritionEntity,@Param("dishesId") Long dishesId); + + /** + * 根据菜品id查询菜品计划详情id + * + * @param dishesIds 菜品id + * @param applyDate 应用日期 + * @return 菜品计划详情id列表 + */ + List selectDishPlanDetailIdByDishId(@Param("dishesIds") Long[] dishesIds,@Param("applyDate") String applyDate); + + /** + * 批量删除菜品信息 + * + * @param detailIdList 菜品计划详情id列表 + * @param dishesIds 菜品id + */ + void deleteCookDishesByDishPlanDetailIds(@Param("detailIdList") List detailIdList,@Param("dishesIds") Long[] dishesIds); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesTypeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesTypeMapper.java index 4f9c4c1..b33697f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesTypeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookDishesTypeMapper.java @@ -2,6 +2,8 @@ package com.bonus.canteen.core.cook.mapper; import java.util.List; import com.bonus.canteen.core.cook.domain.CookDishesType; +import com.bonus.canteen.core.cook.vo.CookDishesTypeVO; +import org.apache.ibatis.annotations.Param; /** * 菜品类型信息Mapper接口 @@ -24,7 +26,7 @@ public interface CookDishesTypeMapper { * @param cookDishesType 菜品类型信息 * @return 菜品类型信息集合 */ - public List selectCookDishesTypeList(CookDishesType cookDishesType); + public List selectCookDishesTypeList(CookDishesType cookDishesType); /** * 新增菜品类型信息 @@ -57,4 +59,21 @@ public interface CookDishesTypeMapper { * @return 结果 */ public int deleteCookDishesTypeByDishesTypeIds(Long[] dishesTypeIds); + /** + * 检查菜品类型名称是否存在 + * + * @param cookDishesType 菜品类型信息 + * @return 结果 + */ + public int checkIsExistByName(CookDishesType cookDishesType); + + /** + * 检查菜品类型是否被使用 + * + * @param dishesTypeIds 菜品类型信息 + * @return 结果 + */ + public int checkIsUse(@Param("dishesTypeIds") Long[] dishesTypeIds); + + List selectList(CookDishesType cookDishesType); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookNutritionMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookNutritionMapper.java index 6dd4955..0616101 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookNutritionMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookNutritionMapper.java @@ -1,8 +1,11 @@ package com.bonus.canteen.core.cook.mapper; import java.util.List; + +import com.bonus.canteen.core.cook.domain.CookDishesMaterial; import com.bonus.canteen.core.cook.domain.CookNutrition; import com.bonus.canteen.core.cook.vo.NutritionTypeVO; +import com.bonus.canteen.core.utils.NutritionEntity; import org.apache.ibatis.annotations.Param; /** @@ -81,4 +84,11 @@ public interface CookNutritionMapper { * @return 结果 */ public int checkIsExistByName(@Param("nutritionName") String nutritionName,@Param("nutritionId") Long nutritionId); + + /** + * 获取食材营养信息 + * @param i 食材信息 + * @return 食材营养信息 + */ + NutritionEntity getNutritionEntity(CookDishesMaterial i); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookDishesTypeService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookDishesTypeService.java index 10ac733..e11fc39 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookDishesTypeService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookDishesTypeService.java @@ -2,6 +2,7 @@ package com.bonus.canteen.core.cook.service; import java.util.List; import com.bonus.canteen.core.cook.domain.CookDishesType; +import com.bonus.canteen.core.cook.vo.CookDishesTypeVO; /** * 菜品类型信息Service接口 @@ -24,7 +25,7 @@ public interface ICookDishesTypeService { * @param cookDishesType 菜品类型信息 * @return 菜品类型信息集合 */ - public List selectCookDishesTypeList(CookDishesType cookDishesType); + public List selectCookDishesTypeList(CookDishesType cookDishesType); /** * 新增菜品类型信息 @@ -57,4 +58,6 @@ public interface ICookDishesTypeService { * @return 结果 */ public int deleteCookDishesTypeByDishesTypeId(Long dishesTypeId); + + List selectList(CookDishesType cookDishesType); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesServiceImpl.java index 674d7be..c205b81 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesServiceImpl.java @@ -1,13 +1,23 @@ package com.bonus.canteen.core.cook.service.impl; +import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.List; + +import com.bonus.canteen.core.cook.domain.CookDishesMaterial; +import com.bonus.canteen.core.cook.mapper.CookNutritionMapper; +import com.bonus.canteen.core.utils.Arith; +import com.bonus.canteen.core.utils.NutritionEntity; +import com.bonus.canteen.core.utils.NutritionEntityUtil; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.core.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.bonus.canteen.core.cook.mapper.CookDishesMapper; import com.bonus.canteen.core.cook.domain.CookDishes; import com.bonus.canteen.core.cook.service.ICookDishesService; +import org.springframework.transaction.annotation.Transactional; /** * 菜品信息Service业务层处理 @@ -19,7 +29,8 @@ import com.bonus.canteen.core.cook.service.ICookDishesService; public class CookDishesServiceImpl implements ICookDishesService { @Autowired private CookDishesMapper cookDishesMapper; - + @Autowired + private CookNutritionMapper cookNutritionMapper; /** * 查询菜品信息 * @@ -49,15 +60,28 @@ public class CookDishesServiceImpl implements ICookDishesService { * @return 结果 */ @Override + @Transactional(rollbackFor = Exception.class) public int insertCookDishes(CookDishes cookDishes) { cookDishes.setCreateTime(DateUtils.getNowDate()); try { - return cookDishesMapper.insertCookDishes(cookDishes); + checkParam(cookDishes,false); + //计算营养信息含量 + //新增菜品名称 + cookDishesMapper.insertDishesName(cookDishes); + //添加菜品 + cookDishesMapper.insertCookDishes(cookDishes); + //添加菜品-原料关联关系 + if (cookDishes.getDishesMaterialList() != null && !cookDishes.getDishesMaterialList().isEmpty()){ + cookDishesMapper.insertDishesMaterial(cookDishes.getDishesMaterialList(), cookDishes.getDishesId()); + calculateNutritionalInfo(cookDishes); + } + return 1; } catch (Exception e) { throw new ServiceException(e.getMessage()); } } + /** * 修改菜品信息 * @@ -65,15 +89,52 @@ public class CookDishesServiceImpl implements ICookDishesService { * @return 结果 */ @Override + @Transactional(rollbackFor = Exception.class) public int updateCookDishes(CookDishes cookDishes) { cookDishes.setUpdateTime(DateUtils.getNowDate()); try { - return cookDishesMapper.updateCookDishes(cookDishes); + checkParam(cookDishes,true); + //修改菜品名称 + cookDishesMapper.updateDishesName(cookDishes); + //修改菜品 + cookDishesMapper.updateCookDishes(cookDishes); + //删除菜品-原料关联关系 + cookDishesMapper.deleteDishesMaterialByDishesId(cookDishes.getDishesId()); + //添加菜品-原料关联关系 + if (cookDishes.getDishesMaterialList() != null && !cookDishes.getDishesMaterialList().isEmpty()){ + cookDishesMapper.insertDishesMaterial(cookDishes.getDishesMaterialList(), cookDishes.getDishesId()); + calculateNutritionalInfo(cookDishes); + } + return 1; } catch (Exception e) { throw new ServiceException(e.getMessage()); } } + public void checkParam(CookDishes cookDishes, boolean isUpdate) { + if (cookDishes.getDishesId() == null && isUpdate) { + throw new ServiceException("菜品ID不能为空"); + } + if (StringUtils.isNull(cookDishes.getAreaId()) || cookDishes.getAreaId() == 0){ + throw new ServiceException("区域不能为空"); + } + if (StringUtils.isNull(cookDishes.getCanteenId()) || cookDishes.getCanteenId() == 0){ + throw new ServiceException("食堂不能为空"); + } + if (StringUtils.isNull(cookDishes.getStallId()) || cookDishes.getStallId() == 0){ + throw new ServiceException("档口不能为空"); + } + if (StringUtils.isNull(cookDishes.getTypeId()) || cookDishes.getTypeId() == 0){ + throw new ServiceException("菜品分类不能为空"); + } + if (StringUtils.isNull(cookDishes.getPrice()) || cookDishes.getPrice() == 0){ + throw new ServiceException("菜品价格不能为空"); + } + if (cookDishesMapper.checkDishIsExist(cookDishes) > 0) { + throw new ServiceException("菜品名称已存在"); + } + } + /** * 批量删除菜品信息 * @@ -82,6 +143,12 @@ public class CookDishesServiceImpl implements ICookDishesService { */ @Override public int deleteCookDishesByDishesIds(Long[] dishesIds) { + //查询所有当天及之后的菜品计划detailId + List detailIdList = cookDishesMapper.selectDishPlanDetailIdByDishId(dishesIds, DateUtils.getDate()); + //删除菜品计划cook_recipe_dishes 菜品计划菜品关联表 + if (detailIdList != null && !detailIdList.isEmpty()){ + cookDishesMapper.deleteCookDishesByDishPlanDetailIds(detailIdList,dishesIds); + } return cookDishesMapper.deleteCookDishesByDishesIds(dishesIds); } @@ -95,4 +162,47 @@ public class CookDishesServiceImpl implements ICookDishesService { public int deleteCookDishesByDishesId(Long dishesId) { return cookDishesMapper.deleteCookDishesByDishesId(dishesId); } + + private void calculateNutritionalInfo(CookDishes cookDishes) { + List dishesMaterialList = cookDishes.getDishesMaterialList(); + List nutritionEntityList = new ArrayList<>(); + for (CookDishesMaterial i : dishesMaterialList) { + NutritionEntity nutritionEntity = cookNutritionMapper.getNutritionEntity(i); + if (nutritionEntity != null) { + System.err.println(i.getMaterialId() + ",开始值:" + nutritionEntity.getCalcium()); + nutritionEntity.setWeight(Double.valueOf(i.getWeight() + "")); + nutritionEntity.setBaseWeight(100.0); + nutritionEntityList.add(nutritionEntity); + } + } + NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList); + if (!nutritionEntityList.isEmpty()) { + System.err.println("总和:" + nutritionEntity.getCalcium()); + //计算营养成分 + countNum(nutritionEntity, Double.valueOf(cookDishes.getWeight() + "")); + System.err.println("计算后:" + nutritionEntity.getCalcium()); + cookDishesMapper.updateFinalNutrition(nutritionEntity, cookDishes.getDishesId()); + } + } + private void 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); + value = Arith.mul(value, proportion); + field.set(nutritionEntity, value); + System.err.println("后来值++++:" + value); + } else { + field.set(nutritionEntity, 0.00); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesTypeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesTypeServiceImpl.java index 169bc20..125bcb3 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesTypeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookDishesTypeServiceImpl.java @@ -1,6 +1,9 @@ package com.bonus.canteen.core.cook.service.impl; +import java.util.Collections; import java.util.List; + +import com.bonus.canteen.core.cook.vo.CookDishesTypeVO; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +41,7 @@ public class CookDishesTypeServiceImpl implements ICookDishesTypeService { * @return 菜品类型信息 */ @Override - public List selectCookDishesTypeList(CookDishesType cookDishesType) { + public List selectCookDishesTypeList(CookDishesType cookDishesType) { return cookDishesTypeMapper.selectCookDishesTypeList(cookDishesType); } @@ -52,6 +55,7 @@ public class CookDishesTypeServiceImpl implements ICookDishesTypeService { public int insertCookDishesType(CookDishesType cookDishesType) { cookDishesType.setCreateTime(DateUtils.getNowDate()); try { + checkParam(cookDishesType, false); return cookDishesTypeMapper.insertCookDishesType(cookDishesType); } catch (Exception e) { throw new ServiceException(e.getMessage()); @@ -68,12 +72,34 @@ public class CookDishesTypeServiceImpl implements ICookDishesTypeService { public int updateCookDishesType(CookDishesType cookDishesType) { cookDishesType.setUpdateTime(DateUtils.getNowDate()); try { + checkParam(cookDishesType, true); return cookDishesTypeMapper.updateCookDishesType(cookDishesType); } catch (Exception e) { throw new ServiceException(e.getMessage()); } } + public void checkParam(CookDishesType cookDishesType, boolean isUpdate) { + if (isUpdate) { + if (cookDishesType.getDishesTypeId() == null) { + throw new ServiceException("菜品分类ID不能为空"); + } + } + if (cookDishesType.getDishesTypeName() == null || cookDishesType.getDishesTypeName().isEmpty()) { + throw new ServiceException("菜品分类名称不能为空"); + } + if (cookDishesTypeMapper.checkIsExistByName(cookDishesType) > 0){ + throw new ServiceException("该菜品分类名称已存在"); + } + if(cookDishesType.getParentId() == null || cookDishesType.getParentId() == 0) { + cookDishesType.setLevel(0L); + }else { + if(cookDishesType.getLevel() == null){ + cookDishesType.setLevel(1L); + } + } + } + /** * 批量删除菜品类型信息 * @@ -82,6 +108,10 @@ public class CookDishesTypeServiceImpl implements ICookDishesTypeService { */ @Override public int deleteCookDishesTypeByDishesTypeIds(Long[] dishesTypeIds) { + // 判断该菜品类型信息是否被使用 + if (cookDishesTypeMapper.checkIsUse(dishesTypeIds) > 0){ + throw new ServiceException("该菜品类型信息被使用,不允许删除!"); + } return cookDishesTypeMapper.deleteCookDishesTypeByDishesTypeIds(dishesTypeIds); } @@ -95,4 +125,9 @@ public class CookDishesTypeServiceImpl implements ICookDishesTypeService { public int deleteCookDishesTypeByDishesTypeId(Long dishesTypeId) { return cookDishesTypeMapper.deleteCookDishesTypeByDishesTypeId(dishesTypeId); } + + @Override + public List selectList(CookDishesType cookDishesType) { + return cookDishesTypeMapper.selectList(cookDishesType); + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookDishesTypeVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookDishesTypeVO.java new file mode 100644 index 0000000..5418a3c --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookDishesTypeVO.java @@ -0,0 +1,21 @@ +package com.bonus.canteen.core.cook.vo; + +import com.bonus.canteen.core.common.domain.BaseTreeNode; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author 19814 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class CookDishesTypeVO extends BaseTreeNode implements Serializable { + @ApiModelProperty(value = "菜品类型ID") + private Long dishesTypeId; + + @ApiModelProperty(value = "菜品类型名称") + private String dishesTypeName; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml index 995cbb2..c7fa74b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml @@ -60,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -73,90 +73,124 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - select dishes_id, meal_type, custom_id, inventory_id, dishes_name, alias_name, bar_code, intro, cook_id, type_id, classify_id, effect_id, style_id, if_local_feature, dishes_depart, sequence, pungency_degree, sales_mode, size_type, size_json, weight, large_weight, little_weight, weight_deviation, price, unit_price, large_price, little_price, image_url, particulars, recommend, index_recommend, like_survey, like_batch, like_num, initial_score, calories, protein, fat, carbohydrate, dietary_fiber, cholesterol, calcium, sodium, purine, iron, iodine, kalium, vitamin_a, vitamin_c, vitamin_e, magnesium, zinc, glycemic_index, sort, canteen_id, shopstall_id, hide_flag, convert_flag, material_cost, gross_profit, gross_profit_rate, public_dishes, area_id, meal_id, create_by, create_time, update_by, update_time from cook_dishes + select dishes_id, meal_type, custom_id, inventory_id, dishes_name, alias_name, bar_code, intro, cook_id, type_id,cdt.dishes_type_name, classify_id, + effect_id, style_id, if_local_feature, dishes_depart, sequence, pungency_degree, sales_mode, size_type, size_json, + weight, large_weight, little_weight, weight_deviation, price, unit_price, large_price, little_price, image_url, + particulars, recommend, index_recommend, like_survey, like_batch, like_num, initial_score, calories, protein, fat, + carbohydrate, dietary_fiber, cholesterol, calcium, sodium, purine, iron, iodine, kalium, vitamin_a, vitamin_c, + vitamin_e, magnesium, zinc, glycemic_index, sort, cd.canteen_id,bc.canteen_name,cd.shopstall_id,bs.stall_name, hide_flag, convert_flag, material_cost, + gross_profit, gross_profit_rate, public_dishes, cd.area_id,ba.area_name, meal_id, cd.create_by, cd.create_time, cd.update_by, cd.update_time + from cook_dishes cd + left join basic_area ba on cd.area_id = ba.area_id + left join basic_canteen bc on cd.canteen_id = bc.canteen_id + left join basic_stall bs on cd.shopstall_id = bs.stall_id + left join cook_dishes_type cdt on cd.type_id = cdt.dishes_type_id - + + + insert into cook_dishes + base_dishes_id, meal_type, custom_id, inventory_id, @@ -212,7 +246,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" glycemic_index, sort, canteen_id, - shopstall_id, + shopstall_id, hide_flag, convert_flag, material_cost, @@ -227,6 +261,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_time, + #{baseDishesId}, #{mealType}, #{customId}, #{inventoryId}, @@ -282,7 +317,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{glycemicIndex}, #{sort}, #{canteenId}, - #{shopstallId}, + #{stallId}, #{hideFlag}, #{convertFlag}, #{materialCost}, @@ -297,6 +332,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{updateTime}, + + insert into cook_dishes_base (dishes_name, create_by, create_time, update_by, update_time) + values (#{dishesName}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}) + + + + insert into cook_dishes_material (dishes_id, material_id, weight,material_type, create_by, create_time, update_by, update_time) + values + + (#{dishesId}, #{item.materialId}, #{item.weight},#{item.materialType}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}) + + update cook_dishes @@ -356,7 +403,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" glycemic_index = #{glycemicIndex}, sort = #{sort}, canteen_id = #{canteenId}, - shopstall_id = #{shopstallId}, + shopstall_id = #{stallId}, hide_flag = #{hideFlag}, convert_flag = #{convertFlag}, material_cost = #{materialCost}, @@ -372,15 +419,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where dishes_id = #{dishesId} + + update cook_dishes_base + + dishes_name = #{dishesName}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where base_dishes_id = #{baseDishesId} + + + update cook_dishes + + calories = #{bean.calories}, + protein = #{bean.protein}, + fat = #{bean.fat}, + carbohydrate = #{bean.carbohydrate}, + dietary_fiber = #{bean.dietaryFiber}, + cholesterol = #{bean.cholesterol}, + calcium = #{bean.calcium}, + sodium = #{bean.sodium}, + purine = #{bean.purine}, + iron = #{bean.iron}, + iodine = #{bean.iodine}, + kalium = #{bean.kalium}, + vitamin_a = #{bean.vitaminA}, + vitamin_c = #{bean.vitaminC}, + vitamin_e = #{bean.vitaminE}, + magnesium = #{bean.magnesium}, + glycemic_index = #{bean.glycemicIndex}, + + where dishes_id = #{dishesId} + delete from cook_dishes where dishes_id = #{dishesId} - delete from cook_dishes where dishes_id in + update cook_dishes set del_flag = '2' where dishes_id in #{dishesId} + + delete from cook_dishes_material where dishes_id = #{dishesId} + + + delete from cook_dishes where dishes_id in + + #{detailId} + + and recipe_detail_id in + + #{detailId} + + \ No newline at end of file diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesTypeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesTypeMapper.xml index cefe289..cfc820c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesTypeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesTypeMapper.xml @@ -21,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select dishes_type_id, dishes_type_name, dishes_type_code, parent_id, level, area_id, dishes_alias_name, create_by, create_time, update_by, update_time from cook_dishes_type - and dishes_type_name like concat('%', #{dishesTypeName}, '%') @@ -37,7 +37,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where dishes_type_id = #{dishesTypeId} - + + + + insert into cook_dishes_type diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookNutritionMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookNutritionMapper.xml index ae35732..b1365de 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookNutritionMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookNutritionMapper.xml @@ -158,6 +158,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from cook_nutrition where nutrition_name = #{nutritionName} and nutrition_id != #{nutritionId} +