From 78c5b00f5d6f62838b2728600ea36d297f1a0356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E5=85=89=EF=BC=81=E9=A3=9E=E5=85=89=EF=BC=81?= <2818288013@qq.com> Date: Tue, 20 Jun 2023 17:06:41 +0800 Subject: [PATCH] =?UTF-8?q?guang:=E5=AE=8C=E6=88=90=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../takeout/controller/SetmealController.java | 59 ++++++++++++++++--- .../modules/takeout/dto/SetmealDTO.java | 14 ++++- .../modules/takeout/dto/SetmealDishDTO.java | 10 ++++ .../takeout/entity/SetmealDishEntity.java | 6 ++ .../modules/takeout/entity/SetmealEntity.java | 6 ++ .../takeout/service/SetmealService.java | 2 - .../service/impl/SetmealServiceImpl.java | 8 --- 7 files changed, 85 insertions(+), 20 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java b/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java index 196754d..31bd553 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.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; import io.renren.common.page.PageData; @@ -10,8 +11,11 @@ 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.SetmealDish; import io.renren.modules.takeout.dto.SetmealDTO; +import io.renren.modules.takeout.dto.SetmealDishDTO; import io.renren.modules.takeout.excel.SetmealExcel; +import io.renren.modules.takeout.service.SetmealDishService; import io.renren.modules.takeout.service.SetmealService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -21,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -43,7 +48,12 @@ import java.util.Map; public class SetmealController { @Autowired private SetmealService setmealService; - + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private SetmealDishService setmealDishService; + @Autowired + private io.renren.modules.front.service.SetmealDishService setmealDishServiceFront; @GetMapping("page") @ApiOperation("分页") @ApiImplicitParams({ @@ -75,9 +85,29 @@ public class SetmealController { public Result save(@RequestBody SetmealDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - + log.info("dto=={}",dto); setmealService.save(dto); - + //保存套餐菜品信息 + List setmealDishes=dto.getSetmealDishes(); + log.info("123456"); + log.info("dishes={}",setmealDishes); + for (SetmealDishDTO setmealDishDTO:setmealDishes){ + log.info("654321"); + log.info("setmealDish={}",setmealDishDTO); +// SetmealDishDTO setmealDishDTO =new SetmealDishDTO(); +//// BeanUtils.copyProperties(setmealDish, setmealDishDTO); + setmealDishDTO.setSetmealId(dto.getId().toString()); +// setmealDishDTO.setCopies(setmealDish.getCopies()); +// setmealDishDTO.setDishId(setmealDish.getDishId()); +// setmealDishDTO.setName(setmealDish.getName()); +// setmealDishDTO.setPrice(setmealDish.getPrice()); + log.info("setmealDishDTO=={}",setmealDishDTO); + setmealDishService.save(setmealDishDTO); +// setmealDish.setSetmealId(dto.getId().toString()); + } +// setmealDishService.insertBatch(setmealDishes); + //清除所有的菜品缓存数据 + redisTemplate.delete("setmeal_*"); return new Result(); } @@ -89,9 +119,16 @@ public class SetmealController { public Result update(@RequestBody SetmealDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); - setmealService.update(dto); - + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(SetmealDish::getSetmealId,dto.getId()); + setmealDishServiceFront.remove(wrapper); + List setmealDishes=dto.getSetmealDishes(); + for (SetmealDishDTO setmealDishDTO:setmealDishes){ + setmealDishDTO.setSetmealId(dto.getId().toString()); + setmealDishService.save(setmealDishDTO); + } //清除所有的菜品缓存数据 + redisTemplate.delete("setmeal_*"); return new Result(); } @@ -103,10 +140,15 @@ public class SetmealController { public Result delete(@RequestBody Long[] ids){ //效验数据 AssertUtils.isArrayEmpty(ids, "id"); - - setmealService.delete(ids); - + //清除SetmealDish + for (Long id:ids){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SetmealDish::getSetmealId,id); + setmealDishServiceFront.remove(wrapper); + } + //清除所有的菜品缓存数据 + redisTemplate.delete("setmeal_*"); return new Result(); } @@ -134,7 +176,6 @@ public class SetmealController { ids.add(value); } } - log.info("ids=-={}",ids); setmealService.updateStatus(ids); return new Result(); } diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDTO.java b/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDTO.java index cf7d727..a35385e 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDTO.java @@ -1,12 +1,18 @@ package io.renren.modules.takeout.dto; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import io.renren.modules.front.bean.Dish; +import io.renren.modules.takeout.entity.SetmealDishEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * 套餐 @@ -44,19 +50,25 @@ public class SetmealDTO implements Serializable { private String image; @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; @ApiModelProperty(value = "是否删除") private Integer isDeleted; - + //菜品的集合 + private List setmealDishes = new ArrayList<>(); +// private List setmealDishEntityList =new ArrayList<>(); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDishDTO.java b/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDishDTO.java index 3ecc8f4..b5fb81b 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDishDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/dto/SetmealDishDTO.java @@ -1,12 +1,17 @@ package io.renren.modules.takeout.dto; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import io.renren.modules.front.bean.Dish; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * 套餐菜品关系 @@ -41,19 +46,24 @@ public class SetmealDishDTO 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; @ApiModelProperty(value = "是否删除") private Integer isDeleted; + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealDishEntity.java b/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealDishEntity.java index 6e9593b..7cdc805 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealDishEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealDishEntity.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; @@ -47,18 +49,22 @@ public class SetmealDishEntity { /** * 创建人 */ + @TableField(fill = FieldFill.INSERT) private Long creator; /** * 创建时间 */ + @TableField(fill = FieldFill.INSERT) private Date createDate; /** * 修改人 */ + @TableField(fill = FieldFill.INSERT_UPDATE) private Long updater; /** * 更新时间 */ + @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; /** * 是否删除 diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealEntity.java b/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealEntity.java index b943197..f72545c 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/entity/SetmealEntity.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; @@ -51,18 +53,22 @@ public class SetmealEntity { /** * 创建人 */ + @TableField(fill = FieldFill.INSERT) private Long creator; /** * 创建时间 */ + @TableField(fill = FieldFill.INSERT) private Date createDate; /** * 修改人 */ + @TableField(fill = FieldFill.INSERT_UPDATE) private Long updater; /** * 更新时间 */ + @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; /** * 是否删除 diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java b/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java index c05720a..13f6af3 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java @@ -13,7 +13,5 @@ import java.util.List; * @since 1.0.0 2023-06-09 */ public interface SetmealService extends CrudService { - - void updateStatus(List ids); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java index 1b80467..6d4c26b 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java @@ -21,7 +21,6 @@ import java.util.Map; * @author zyx * @since 1.0.0 2023-06-09 */ -@Slf4j @Service public class SetmealServiceImpl extends CrudServiceImpl implements SetmealService { @@ -37,13 +36,8 @@ public class SetmealServiceImpl extends CrudServiceImpl ids) { - if (ids == null || ids.isEmpty()) { - log.info("ids==null----"); - return; - } if (ids.size()>1){ int index =Integer.parseInt(ids.get(0)) ; - log.info("index=={}",index); for (int i = 1; i < ids.size(); i++) { Long id =Long.parseLong(ids.get(i)) ; SetmealEntity setmeal = this.selectById(id); @@ -53,7 +47,6 @@ public class SetmealServiceImpl extends CrudServiceImpl