package cn.iocoder.yudao.module.system.service.restaurant;

import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.system.dal.dataobject.restaurant.RestaurantManagementDO;
import cn.iocoder.yudao.module.system.dal.mysql.restaurant.RestaurantManagementMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 餐厅管理 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class RestaurantManagementServiceImpl implements RestaurantManagementService {

    @Resource
    private RestaurantManagementMapper restaurantManagementMapper;


    @Override
    public Long createRestaurantManagement(RestaurantManagementDO createReqVO) {
        createReqVO.setCreatedBy(SecurityFrameworkUtils.getLoginUserNickname());
        createReqVO.setCreatedTime(LocalDateTime.now());
        restaurantManagementMapper.insert(createReqVO);
        return createReqVO.getId();
    }

    @Override
    public List<RestaurantManagementDO> getList(Integer orgType, Long tenantId) {
        return restaurantManagementMapper.selectList(new LambdaQueryWrapperX<RestaurantManagementDO>()
                .eqIfPresent(RestaurantManagementDO::getOrgType, orgType)
                .eqIfPresent(RestaurantManagementDO::getTenantId, tenantId)
                .orderByDesc(RestaurantManagementDO::getCreatedTime));
    }

    @Override
    public void updateRestaurantManagement(RestaurantManagementDO updateReqVO) {
        restaurantManagementMapper.updateById(updateReqVO);
    }

    @Override
    public void deleteRestaurantManagement(Long id) {
        restaurantManagementMapper.deleteById(id);
    }
}