guang:完成套餐部分

This commit is contained in:
飞光!飞光! 2023-06-20 17:06:41 +08:00
parent 5ce6e3ccc7
commit 78c5b00f5d
7 changed files with 85 additions and 20 deletions

View File

@ -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<SetmealDishDTO> 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<SetmealDish> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SetmealDish::getSetmealId,dto.getId());
setmealDishServiceFront.remove(wrapper);
List<SetmealDishDTO> 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<SetmealDish> 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();
}

View File

@ -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<SetmealDishDTO> setmealDishes = new ArrayList<>();
// private List<SetmealDishEntity> setmealDishEntityList =new ArrayList<>();
}

View File

@ -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;
}

View File

@ -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;
/**
* 是否删除

View File

@ -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;
/**
* 是否删除

View File

@ -13,7 +13,5 @@ import java.util.List;
* @since 1.0.0 2023-06-09
*/
public interface SetmealService extends CrudService<SetmealEntity, SetmealDTO> {
void updateStatus(List<String> ids);
}

View File

@ -21,7 +21,6 @@ import java.util.Map;
* @author zyx
* @since 1.0.0 2023-06-09
*/
@Slf4j
@Service
public class SetmealServiceImpl extends CrudServiceImpl<SetmealDao, SetmealEntity, SetmealDTO> implements SetmealService {
@ -37,13 +36,8 @@ public class SetmealServiceImpl extends CrudServiceImpl<SetmealDao, SetmealEntit
@Override
public void updateStatus(List<String> 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<SetmealDao, SetmealEntit
}else {
Long id =Long.parseLong(ids.get(0)) ;
SetmealEntity setmeal = this.selectById(id);
log.info("SetmealEntity111={}",setmeal);
if (setmeal.getStatus().equals(1)){
setmeal.setStatus(0);
this.updateById(setmeal);
@ -62,7 +55,6 @@ public class SetmealServiceImpl extends CrudServiceImpl<SetmealDao, SetmealEntit
setmeal.setStatus(1);
this.updateById(setmeal);
}
log.info("SetmealEntity222={}",setmeal);
}
}
}