From 485142fdd87c5d5b287cb8a8a46171c3ee0c7277 Mon Sep 17 00:00:00 2001 From: mlf9527 <2192316287@qq.com> Date: Mon, 19 Jun 2023 18:26:29 +0800 Subject: [PATCH] =?UTF-8?q?6/19=20=E5=AE=8C=E5=96=84=E4=BA=86=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=88=A0=E9=99=A4=E5=8F=8A=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E5=A1=AB=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryController.java | 35 ++++++++++++++----- .../modules/takeout/dto/CategoryDTO.java | 7 +++- .../takeout/entity/CategoryEntity.java | 15 +++++--- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/controller/CategoryController.java b/renren-admin/src/main/java/io/renren/modules/takeout/controller/CategoryController.java index 495857e..5803e7c 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/controller/CategoryController.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/controller/CategoryController.java @@ -1,5 +1,6 @@ package io.renren.modules.takeout.controller; + import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import io.renren.common.annotation.LogOperation; import io.renren.common.constant.Constant; @@ -11,16 +12,14 @@ import io.renren.common.validator.ValidatorUtils; import io.renren.common.validator.group.AddGroup; import io.renren.common.validator.group.DefaultGroup; import io.renren.common.validator.group.UpdateGroup; -import io.renren.modules.front.bean.Category; -import io.renren.modules.front.utils.R; +import io.renren.modules.front.bean.Dish; +import io.renren.modules.front.bean.Setmeal; +import io.renren.modules.front.service.DishService; +import io.renren.modules.front.service.SetmealService; import io.renren.modules.takeout.dto.CategoryDTO; -import io.renren.modules.takeout.entity.CategoryEntity; import io.renren.modules.takeout.excel.CategoryExcel; import io.renren.modules.takeout.service.CategoryService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.*; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -43,6 +42,10 @@ import java.util.Map; public class CategoryController { @Autowired private CategoryService categoryService; + @Autowired + private DishService dishService; + @Autowired + private SetmealService setmealService; @GetMapping("list") public Result> list(@RequestParam Map params){ @@ -87,6 +90,7 @@ public class CategoryController { return new Result(); } + @PutMapping @ApiOperation("修改") @LogOperation("修改") @@ -107,7 +111,22 @@ public class CategoryController { public Result delete(@RequestBody Long[] ids){ //效验数据 AssertUtils.isArrayEmpty(ids, "id"); - + for (Long id : ids) { + CategoryDTO categoryDTO=categoryService.get(id); + if(categoryDTO.getType()==1){ + LambdaQueryWrapper wrapper=new LambdaQueryWrapper<>(); + wrapper.eq(Dish::getCategoryId,id); + if (!dishService.list(wrapper).isEmpty()) { + return new Result().error("存在分类含有菜品或套餐!"); + } + }else { + LambdaQueryWrapper wrapper=new LambdaQueryWrapper<>(); + wrapper.eq(Setmeal::getCategoryId,id); + if(!setmealService.list(wrapper).isEmpty()){ + return new Result().error("存在分类含有菜品或套餐!"); + } + } + } categoryService.delete(ids); return new Result(); diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/dto/CategoryDTO.java b/renren-admin/src/main/java/io/renren/modules/takeout/dto/CategoryDTO.java index 6930949..b422c2b 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/dto/CategoryDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/dto/CategoryDTO.java @@ -1,5 +1,7 @@ package io.renren.modules.takeout.dto; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -32,16 +34,19 @@ public class CategoryDTO implements Serializable { private Integer sort; @ApiModelProperty(value = "创建人") + @TableField(fill = FieldFill.INSERT) private Long creator; @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) private Date createDate; @ApiModelProperty(value = "修改人") + @TableField(fill = FieldFill.INSERT_UPDATE) private Long updater; @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; - } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/entity/CategoryEntity.java b/renren-admin/src/main/java/io/renren/modules/takeout/entity/CategoryEntity.java index a23ca27..6a21cbb 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/entity/CategoryEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/entity/CategoryEntity.java @@ -1,5 +1,7 @@ package io.renren.modules.takeout.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -34,17 +36,22 @@ public class CategoryEntity { /** * 创建人 */ - private Long creator; + @TableField(fill = FieldFill.INSERT) + private Long creator; /** * 创建时间 */ - private Date createDate; + @TableField(fill = FieldFill.INSERT) + private Date createDate; /** * 修改人 */ - private Long updater; + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; /** * 更新时间 */ - private Date updateDate; + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + } \ No newline at end of file