菜品分页查询
This commit is contained in:
parent
ed298ec39b
commit
af53702e96
|
@ -1,15 +1,14 @@
|
||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@ -29,9 +28,17 @@ public class DishController {
|
||||||
*/
|
*/
|
||||||
@ApiOperation("新增菜品")
|
@ApiOperation("新增菜品")
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public Result<String > save(@RequestBody DishDTO dishDTO) {
|
public Result<String> save(@RequestBody DishDTO dishDTO) {
|
||||||
log.info("新增菜品:{}", dishDTO);
|
log.info("新增菜品:{}", dishDTO);
|
||||||
dishService.saveWithFlavor(dishDTO);
|
dishService.saveWithFlavor(dishDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("菜品分页查询")
|
||||||
|
@GetMapping("/page")
|
||||||
|
public Result<PageResult> pageResultResult(DishPageQueryDTO dishPageQueryDTO) {
|
||||||
|
log.info("菜品分页查询:{}", dishPageQueryDTO);
|
||||||
|
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
import com.sky.annotation.AutoFill;
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
import com.sky.entity.Dish;
|
import com.sky.entity.Dish;
|
||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@ -24,4 +27,11 @@ public interface DishMapper {
|
||||||
*/
|
*/
|
||||||
@AutoFill(value = OperationType.INSERT)
|
@AutoFill(value = OperationType.INSERT)
|
||||||
void insert(Dish dish);
|
void insert(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param dishPageQueryDTO DishPageQueryDTO
|
||||||
|
* @return Page<DishVO>
|
||||||
|
*/
|
||||||
|
Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
|
||||||
public interface DishService {
|
public interface DishService {
|
||||||
/**
|
/**
|
||||||
|
@ -9,4 +11,11 @@ public interface DishService {
|
||||||
* @param dishDTO DishDTO
|
* @param dishDTO DishDTO
|
||||||
*/
|
*/
|
||||||
void saveWithFlavor(DishDTO dishDTO);
|
void saveWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param dishPageQueryDTO DishPageQueryDTO
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
import com.sky.entity.Dish;
|
import com.sky.entity.Dish;
|
||||||
import com.sky.entity.DishFlavor;
|
import com.sky.entity.DishFlavor;
|
||||||
import com.sky.mapper.DishFlavorMapper;
|
import com.sky.mapper.DishFlavorMapper;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -46,4 +51,16 @@ public class DishServiceImpl implements DishService {
|
||||||
dishFlavorMapper.insertBatch(flavors);
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param dishPageQueryDTO DishPageQueryDTO
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
|
||||||
|
PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
|
||||||
|
Page<DishVO> page = dishMapper.pageQuery(dishPageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(),page.getResult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,28 @@
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<!-- 根据分类id查询菜品数量 -->
|
<!-- 根据分类id查询菜品数量 -->
|
||||||
<select id="countByCategoryId" resultType="java.lang.Integer" >
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
select count(id)
|
select count(id)
|
||||||
from dish
|
from dish
|
||||||
where category_id = #{categoryId}
|
where category_id = #{categoryId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 菜品分页查询 -->
|
||||||
|
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||||
|
select d.*, c.name as categoryName
|
||||||
|
from dish d
|
||||||
|
left OUTER join category c on d.category_id = c.id
|
||||||
|
<where>
|
||||||
|
<if test="name != null">
|
||||||
|
and d.name like concat("%",#{name},"%")
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
and d.category_id = #{categoryId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and d.status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by d.create_time desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue