#7 添加 'DishService.java'

Merged
WuTianJuan merged 1 commits from wutianjuan-patch-3 into master 1 year ago
  1. +1155
    -0
      DishService.java

+ 1155
- 0
DishService.java View File

@@ -0,0 +1,1155 @@

@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}
package com.damowang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.damowang.common.R;
import com.damowang.dto.DishDto;
import com.damowang.entity.Category;
import com.damowang.entity.Dish;
import com.damowang.service.CategoryService;
import com.damowang.service.DishFlavorService;
import com.damowang.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
* @author Demon King
* @create 2022-06-29 20:34
*/
@RestController
@RequestMapping("/dish")
public class DishController {
@Autowired
private DishService dishService;

@Autowired
private CategoryService categoryService;

@PostMapping
public R<String> savaWithFlavor(@RequestBody DishDto dishDto){
dishService.savaWithFlavor(dishDto);
return R.success("菜品添加成功");
}

//进行菜品管理的分页查询
@GetMapping("/page")
public R<Page<DishDto>> list(int page,int pageSize,String name){
Page<Dish> ipage = new Page<>(page,pageSize);

LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper();
lqw.eq(name!=null,Dish::getName,name).orderByDesc(Dish::getUpdateTime);

dishService.page(ipage,lqw);

Page<DishDto> Rpage = new Page<>(page,pageSize);

//进行拷贝,忽略查询的内容
BeanUtils.copyProperties(ipage,Rpage,"records");

List<Dish> records = ipage.getRecords();
List<DishDto> records1 = new ArrayList<>();
for (Dish dish :
records) {
Long categoryId = dish.getCategoryId();
DishDto dishDto = new DishDto();
//通过id查询对应的名字
if (categoryId!=null){
String name1 = categoryService.getById(categoryId).getName();
dishDto.setCategoryName(name1);
}

BeanUtils.copyProperties(dish,dishDto);
records1.add(dishDto);
}
Rpage.setRecords(records1);
return R.success(Rpage);
}

//删除某样菜品
@DeleteMapping
public R<String> deleteById(long ids){
dishService.deleteByMyId(ids);
return R.success("删除成功");

}



//回显数据
@GetMapping("/{id}")
public R<DishDto> selectByid(@PathVariable long id){
R<DishDto> dishDtoR = dishService.selectByid(id);
return dishDtoR;
}

//更新菜品
@PutMapping
public R<DishDto> updateWithFlavor(@RequestBody DishDto dishDto){

return null;

}

//套餐菜品中的显示添加菜品
@GetMapping("/list")
public R<List<Dish>> list(long categoryId){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId,categoryId).eq(Dish::getStatus,1);
List<Dish> list = dishService.list(lqw);
return R.success(list);


}
}

Loading…
Cancel
Save