根据id查询套餐
This commit is contained in:
parent
25cf3769ec
commit
97de686244
|
@ -5,6 +5,7 @@ import com.sky.dto.SetmealPageQueryDTO;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.SetmealService;
|
import com.sky.service.SetmealService;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
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;
|
||||||
|
@ -13,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController("adminRestController")
|
||||||
@RequestMapping("/admin/setmeal")
|
@RequestMapping("/admin/setmeal")
|
||||||
@Api(tags = "套餐相关接口")
|
@Api(tags = "套餐相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -73,4 +74,30 @@ public class SetmealController {
|
||||||
setmealService.delete(ids);
|
setmealService.delete(ids);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐
|
||||||
|
*
|
||||||
|
* @param id Long
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据id查询套餐")
|
||||||
|
@GetMapping("{id}")
|
||||||
|
public Result getById(@PathVariable Long id) {
|
||||||
|
SetmealVO setmealVO = setmealService.getById(id);
|
||||||
|
return Result.success(setmealVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@ApiOperation("修改套餐")
|
||||||
|
@PutMapping()
|
||||||
|
public Result update(@RequestBody SetmealDTO setmealDTO) {
|
||||||
|
setmealService.update(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,4 +59,12 @@ public interface SetMealDishMapper {
|
||||||
* @param setmealId Long
|
* @param setmealId Long
|
||||||
*/
|
*/
|
||||||
void deleteBySetmealId(Long setmealId);
|
void deleteBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据套餐id查询套餐和菜品的关联关系
|
||||||
|
*
|
||||||
|
* @param id Long
|
||||||
|
* @return List<SetmealDish>
|
||||||
|
*/
|
||||||
|
List<SetmealDish> getBySetmealId(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.sky.dto.SetmealPageQueryDTO;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -56,4 +57,19 @@ public interface SetmealService {
|
||||||
* @param ids List<Long>
|
* @param ids List<Long>
|
||||||
*/
|
*/
|
||||||
void delete(List<Long> ids);
|
void delete(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐
|
||||||
|
*
|
||||||
|
* @param id Long
|
||||||
|
* @return SetmealVO
|
||||||
|
*/
|
||||||
|
SetmealVO getById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
*/
|
||||||
|
void update(SetmealDTO setmealDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,4 +144,46 @@ public class SetmealServiceImpl implements SetmealService {
|
||||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐
|
||||||
|
*
|
||||||
|
* @param id Long
|
||||||
|
* @return SetmealVO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SetmealVO getById(Long id) {
|
||||||
|
Setmeal setmeal = setmealMapper.getById(id);
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.getBySetmealId(id);
|
||||||
|
|
||||||
|
SetmealVO setmealVO = new SetmealVO();
|
||||||
|
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||||
|
setmealVO.setSetmealDishes(setmealDishes);
|
||||||
|
return setmealVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void update(SetmealDTO setmealDTO) {
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
|
||||||
|
// 1、修改套餐表,执行update
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
|
||||||
|
// 套餐id
|
||||||
|
Long setmealId = setmealDTO.getId();
|
||||||
|
// 2、删除套餐和菜品的关联关系,操作setmeal_dish表,执行delete
|
||||||
|
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
setmealDishes.forEach(setmealDish -> {
|
||||||
|
setmealDish.setSetmealId(setmealId);
|
||||||
|
});
|
||||||
|
// 3、重新插入套餐和菜品的关联关系,操作setmeal_dish表,执行insert
|
||||||
|
setmealDishMapper.insertBatch(setmealDishes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,11 @@
|
||||||
</where>
|
</where>
|
||||||
order by s.create_time desc
|
order by s.create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据套餐id查询套餐和菜品的关联关系 -->
|
||||||
|
<select id="getBySetmealId" resultType="com.sky.entity.SetmealDish">
|
||||||
|
select *
|
||||||
|
from setmeal_dish
|
||||||
|
where setmeal_id = #{setmealId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue