package com.sdut.labex.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.TimeOption;
import com.sdut.labex.mapper.TimeOptionMapper;
import com.sdut.labex.service.TimeOptionService;
import com.sdut.labex.utils.ResVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author springforest
 * @description 针对表【timeOption(时间)】的数据库操作Service实现
 * @createDate 2023-06-12 08:07:15
 */
@Service
public class TimeOptionServiceImpl extends ServiceImpl<TimeOptionMapper, TimeOption>
        implements TimeOptionService {
    @Resource
    private TimeOptionMapper timeOptionMapper;

    @Override
    public ResVo addTimeOption(TimeOption timeOption) {
        try {
            timeOptionMapper.insert(timeOption);
        } catch (Exception e) {
            e.printStackTrace();
            return ResVo.error("添加失败");
        }
        return ResVo.ok("添加成功");
    }

    @Override
    public ResVo deleteTimeOption(int id) {
        try {
            timeOptionMapper.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return ResVo.error("删除失败");
        }
        return ResVo.ok("删除成功");
    }

    @Override
    public ResVo updateTimeOption(TimeOption timeOption) {
        try {
            timeOptionMapper.updateById(timeOption);
        } catch (Exception e) {
            e.printStackTrace();
            return ResVo.error("更新失败");
        }
        return ResVo.ok("更新成功");
    }

    @Override
    public ResVo getTimeOptions() {
        List<TimeOption> list = timeOptionMapper.selectList(null);
        Map<String, Object> res = new HashMap<>();
        res.put("list", list);
        return ResVo.ok(res);
    }
}




