修改菜品
This commit is contained in:
parent
821819ed5c
commit
a3218d4b3a
|
@ -75,4 +75,17 @@ public class DishController {
|
||||||
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||||
return Result.success(dishVO);
|
return Result.success(dishVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品
|
||||||
|
* @param dishDTO DishDTO
|
||||||
|
* @return Result<String>
|
||||||
|
*/
|
||||||
|
@ApiOperation("修改菜品")
|
||||||
|
@PutMapping()
|
||||||
|
public Result<String> update(@RequestBody DishDTO dishDTO) {
|
||||||
|
log.info("修改菜品:{}", dishDTO);
|
||||||
|
dishService.updateWithFlavor(dishDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,4 +55,11 @@ public interface DishMapper {
|
||||||
* @param ids List<Long>
|
* @param ids List<Long>
|
||||||
*/
|
*/
|
||||||
void deleteByIds(List<Long> ids);
|
void deleteByIds(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除原有口味数据
|
||||||
|
* @param dish Dish
|
||||||
|
*/
|
||||||
|
@AutoFill(value = OperationType.UPDATE)
|
||||||
|
void update(Dish dish);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,10 @@ public interface DishService {
|
||||||
* @return DishVO
|
* @return DishVO
|
||||||
*/
|
*/
|
||||||
DishVO getByIdWithFlavor(Long id);
|
DishVO getByIdWithFlavor(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品
|
||||||
|
* @param dishDTO DishDTO
|
||||||
|
*/
|
||||||
|
void updateWithFlavor(DishDTO dishDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,15 @@ import com.sky.mapper.DishFlavorMapper;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
import com.sky.mapper.SetMealDishMapper;
|
import com.sky.mapper.SetMealDishMapper;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
import com.sky.vo.DishVO;
|
import com.sky.vo.DishVO;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
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;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -117,4 +120,29 @@ public class DishServiceImpl implements DishService {
|
||||||
|
|
||||||
return dishVO;
|
return dishVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品
|
||||||
|
*
|
||||||
|
* @param dishDTO DishDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateWithFlavor(DishDTO dishDTO) {
|
||||||
|
// 修改菜品基本信息
|
||||||
|
Dish dish = new Dish();
|
||||||
|
BeanUtils.copyProperties(dishDTO, dish);
|
||||||
|
// 删除原有口味数据
|
||||||
|
dishMapper.update(dish);
|
||||||
|
// 重新插入口味数据
|
||||||
|
dishFlavorMapper.deleteByDishId(dishDTO.getId());
|
||||||
|
// 重新插入新的口味数据
|
||||||
|
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||||
|
if (flavors != null && !flavors.isEmpty()) {
|
||||||
|
flavors.forEach(dishFlavor -> {
|
||||||
|
dishFlavor.setDishId(dishDTO.getId());
|
||||||
|
});
|
||||||
|
// 向表中插入n条数据
|
||||||
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,38 @@
|
||||||
#{updateTime}, #{createUser}, #{updateUser});
|
#{updateTime}, #{createUser}, #{updateUser});
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<!-- 删除原有口味数据 -->
|
||||||
|
<update id="update">
|
||||||
|
update dish
|
||||||
|
<set>
|
||||||
|
<if test="name != null">
|
||||||
|
name = #{name},
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
category_id = #{categoryId},
|
||||||
|
</if>
|
||||||
|
<if test="price != null">
|
||||||
|
price = #{price},
|
||||||
|
</if>
|
||||||
|
<if test="image != null">
|
||||||
|
image = #{image},
|
||||||
|
</if>
|
||||||
|
<if test="description != null">
|
||||||
|
description = #{description},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status},
|
||||||
|
</if>
|
||||||
|
<if test="updateTime != null">
|
||||||
|
update_time = #{updateTime},
|
||||||
|
</if>
|
||||||
|
<if test="updateUser != null">
|
||||||
|
update_user = #{updateUser},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 删除菜品表中的菜品数据 -->
|
<!-- 删除菜品表中的菜品数据 -->
|
||||||
<delete id="deleteById">
|
<delete id="deleteById">
|
||||||
delete
|
delete
|
||||||
|
|
Loading…
Reference in New Issue