package com.ruoyi.mall.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.OfflineServicesMapper;
import com.ruoyi.mall.domain.OfflineServices;
import com.ruoyi.mall.service.IOfflineServicesService;

import javax.annotation.Resource;

/**
 * 线下服务Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-16
 */
@Service
public class OfflineServicesServiceImpl implements IOfflineServicesService 
{
    @Resource
    private OfflineServicesMapper offlineServicesMapper;

    /**
     * 查询线下服务
     * 
     * @param serviceId 线下服务主键
     * @return 线下服务
     */
    @Override
    public OfflineServices selectOfflineServicesByServiceId(Long serviceId)
    {
        return offlineServicesMapper.selectOfflineServicesByServiceId(serviceId);
    }

    /**
     * 查询线下服务列表
     * 
     * @param offlineServices 线下服务
     * @return 线下服务
     */
    @Override
    public List<OfflineServices> selectOfflineServicesList(OfflineServices offlineServices)
    {
        return offlineServicesMapper.selectOfflineServicesList(offlineServices);
    }

    /**
     * 新增线下服务
     * 
     * @param offlineServices 线下服务
     * @return 结果
     */
    @Override
    public int insertOfflineServices(OfflineServices offlineServices)
    {
        // 获取登陆用户
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        offlineServices.setCreateBy(loginUser.getUsername());
        offlineServices.setCreateTime(DateUtils.getNowDate());
        return offlineServicesMapper.insertOfflineServices(offlineServices);
    }

    /**
     * 修改线下服务
     * 
     * @param offlineServices 线下服务
     * @return 结果
     */
    @Override
    public int updateOfflineServices(OfflineServices offlineServices)
    {
        // 获取登陆用户
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        offlineServices.setUpdateBy(loginUser.getUsername());
        offlineServices.setUpdateTime(DateUtils.getNowDate());
        return offlineServicesMapper.updateOfflineServices(offlineServices);
    }

    /**
     * 逻辑 批量删除线下服务
     * 
     * @param serviceIds 需要删除的线下服务主键
     * @return 结果
     */
    @Override
    public int logicDelOfflineServicesByServiceIds(Long[] serviceIds)
    {
        // 获取登陆用户
        LoginUser loginUser = SecurityUtils.getLoginUser();
        OfflineServices offlineServices = new OfflineServices();
        offlineServices.setUpdateTime(DateUtils.getNowDate());
        offlineServices.setUpdateBy(loginUser.getUsername());
        offlineServices.setDelFlag("2");
        return offlineServicesMapper.logicDelOfflineServicesByServiceIds(serviceIds,offlineServices);
    }

    @Override
    public int logicDelOfflineServicesByServiceId(Long serviceIds)
    {
        // 获取登陆用户
        LoginUser loginUser = SecurityUtils.getLoginUser();
        OfflineServices offlineServices = new OfflineServices();
        offlineServices.setUpdateTime(DateUtils.getNowDate());
        offlineServices.setUpdateBy(loginUser.getUsername());
        offlineServices.setDelFlag("2");
        return offlineServicesMapper.logicDelOfflineServicesByServiceId(offlineServices);
    }


}
