package com.duowenlvshi.duowenlszp.model.Meal.server;

import com.duowenlvshi.duowenlszp.model.Meal.entity.Meal;
import com.duowenlvshi.duowenlszp.app.util.UUIDUtil;
import com.duowenlvshi.duowenlszp.model.Meal.dao.MealMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author yang fang yu
 * @since 2019/9/9 20:33
 */
@Service
public class MealServer {
    @Autowired(required = false)
    MealMapper mealMapper;

    public int save(Meal meal){
        int i;
        if("".equals(meal.getId())){
            //新增
            meal.setId(UUIDUtil.GetUUID());
            meal.setCreatedate(new Date());
            meal.setUpdatedate(new Date());
            meal.setIsvalid("1");
            i =mealMapper.insertSelective(meal);
        }else{
            //修改
            i =mealMapper.updateSelective(meal);
        }
        return i;
    }

    public Meal selectMeal(String id){
        return mealMapper.selectMeal(id);
    }
    public Map selectMealType(String mealType){
        return mealMapper.selectMealType(mealType);
    }

    public Integer selectPurchaseNuml(String id){
        return mealMapper.selectPurchaseNuml(id);
    }
    public Integer selectIsFree(String id){
        return mealMapper.selectIsFree(id);
    }

    public Integer updatePurchaseNuml(Map map){
        return mealMapper.updatePurchaseNuml(map);
    }
    public List<Map> selectMealList(){
        return mealMapper.selectMealList();
    }
    public String selectDiscount(){
        return mealMapper.selectDiscount();
    }
}
