优化
This commit is contained in:
@ -174,6 +174,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CARTEEN_NOT_EXISt = new ErrorCode(1_002_029_002, "当前门店不存在");
|
||||
// ========== 菜品管理 1-002-030-000 ==========
|
||||
ErrorCode DISHES_NOT_EXISTS = new ErrorCode(1_002_030_002, "当前菜品不存在");
|
||||
ErrorCode DISHES_EXISTS = new ErrorCode(1_002_030_003, "菜品名重复");
|
||||
// ========== 菜品关联门店 1-002-032-000 ==========
|
||||
ErrorCode DISHES_TYPE_NOT_EXISTS = new ErrorCode(1_002_032_002, "当前菜品类型不存在");
|
||||
// ========== 门店 流水 1_002_033_002 ==========
|
||||
|
@ -30,6 +30,8 @@ public interface DishesMapper extends BaseMapperX<DishesDO> {
|
||||
.eqIfPresent(DishesDO::getDishesVipWeighPrice, reqVO.getDishesVipWeighPrice())
|
||||
.eqIfPresent(DishesDO::getDishecCook, reqVO.getDishecCook())
|
||||
.eqIfPresent(DishesDO::getDishecType, reqVO.getDishecType())
|
||||
.eqIfPresent(DishesDO::getWeekTime, reqVO.getWeekTime())
|
||||
.eqIfPresent(DishesDO::getTimeSlot,reqVO.getTimeSlot())
|
||||
.inIfPresent(DishesDO::getWeekTime, reqVO.getWeekTimes())
|
||||
.betweenIfPresent(DishesDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(DishesDO::getId));
|
||||
|
@ -69,7 +69,7 @@ public class DishesServiceImpl implements DishesService {
|
||||
DishesDO dishes = BeanUtils.toBean(createReqVO, DishesDO.class);
|
||||
dishes.setDeleted(Boolean.FALSE);
|
||||
|
||||
checkDishes(dishes.getDishesName(),dishes.getCarteenId());
|
||||
checkDishes(dishes.getDishesName(),dishes.getCarteenId(),null);
|
||||
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
int hour = today.getHour();
|
||||
@ -117,7 +117,7 @@ public class DishesServiceImpl implements DishesService {
|
||||
dishes.setCarteenId(carteenId);
|
||||
dishes.setDishesNumber(new BigDecimal("50"));
|
||||
|
||||
checkDishes(dishes.getDishesName(),dishes.getCarteenId());
|
||||
checkDishes(dishes.getDishesName(),dishes.getCarteenId(),null);
|
||||
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
int hour = today.getHour();
|
||||
@ -148,7 +148,7 @@ public class DishesServiceImpl implements DishesService {
|
||||
// 更新
|
||||
DishesDO updateObj = BeanUtils.toBean(updateReqVO, DishesDO.class);
|
||||
|
||||
checkDishes(updateObj.getDishesName(),updateObj.getCarteenId());
|
||||
checkDishes(updateObj.getDishesName(),updateObj.getCarteenId(),updateReqVO.getId());
|
||||
|
||||
//计算每g多少钱
|
||||
BigDecimal dishesSumPrice = updateObj.getDishesSumPrice();
|
||||
@ -175,10 +175,10 @@ public class DishesServiceImpl implements DishesService {
|
||||
|
||||
@Override
|
||||
public void updateDishesApp(AppUpdateVO vo) {
|
||||
validateDishesExists(vo.getId());
|
||||
DishesDO dishesDO = validateDishesExists(vo.getId());
|
||||
DishesDO updateObj = BeanUtils.toBean(vo, DishesDO.class);
|
||||
|
||||
checkDishes(updateObj.getDishesName(),updateObj.getCarteenId());
|
||||
checkDishes(updateObj.getDishesName(),dishesDO.getCarteenId(),vo.getId());
|
||||
|
||||
//计算每g多少钱
|
||||
BigDecimal dishesSumPrice = updateObj.getDishesSumPrice();
|
||||
@ -201,10 +201,12 @@ public class DishesServiceImpl implements DishesService {
|
||||
dishesMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateDishesExists(Long id) {
|
||||
if (dishesMapper.selectById(id) == null) {
|
||||
private DishesDO validateDishesExists(Long id) {
|
||||
DishesDO dishesDO = dishesMapper.selectById(id);
|
||||
if ( dishesDO == null) {
|
||||
throw exception(ErrorCodeConstants.DISHES_NOT_EXISTS);
|
||||
}
|
||||
return dishesDO;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,13 +310,13 @@ public class DishesServiceImpl implements DishesService {
|
||||
}
|
||||
|
||||
|
||||
void checkDishes(String dishName,Long carteenId){
|
||||
void checkDishes(String dishName,Long carteenId,Long id){
|
||||
List<DishesDO> dishesDOS = dishesMapper.selectList(Wrappers.<DishesDO>lambdaQuery()
|
||||
.eq(DishesDO::getCarteenId, carteenId)
|
||||
.eq(DishesDO::getDishesName, dishName));
|
||||
|
||||
.eq(DishesDO::getDishesName, dishName)
|
||||
.ne(id!=null, DishesDO::getId, id));
|
||||
if(!dishesDOS.isEmpty()){
|
||||
throw exception(2000_10_002, "菜品名称已存在");
|
||||
throw exception(ErrorCodeConstants.DISHES_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user