package com.hfkj.service.quiz.impl;

import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsOilPriceQuizRewardMapper;
import com.hfkj.entity.BsOilPriceQuizReward;
import com.hfkj.service.quiz.BsOilPriceQuizRewardService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsOilPriceQuizRewardServiceImpl
 * @author: HuRui
 * @date: 2025/11/25
 **/
@Service("oilPriceQuizRewardService")
public class BsOilPriceQuizRewardServiceImpl implements BsOilPriceQuizRewardService {
    @Resource
    private BsOilPriceQuizRewardMapper oilPriceQuizRewardMapper;


    @Override
    public void edit(BsOilPriceQuizReward data) {
        data.setUpdateTime(new Date());
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            data.setStatus(1);
            oilPriceQuizRewardMapper.insert(data);
        } else {
            oilPriceQuizRewardMapper.updateByPrimaryKey(data);
        }
    }

    @Override
    public BsOilPriceQuizReward getDetail(Long id) {
        return oilPriceQuizRewardMapper.selectByPrimaryKey(id);
    }

    @Override
    public void del(Long id) {
        // 查询详情
        BsOilPriceQuizReward detail = getDetail(id);
        if (detail == null) {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
        }
        detail.setStatus(0);
        edit(detail);
    }

    @Override
    public List<HashMap<String, Object>> getList(Map<String, Object> param) {
        return oilPriceQuizRewardMapper.queryList(param);
    }
}
