package cn.wisenergy.service.app.impl;

import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.CultivatingPrizeMapper;
import cn.wisenergy.model.app.CultivatingPrize;
import cn.wisenergy.model.vo.CultivatingPrizeVo;
import cn.wisenergy.model.vo.SetCultivatingVo;
import cn.wisenergy.service.app.CultivatingPrizeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by m1991 on 2021/3/26 11:06
 */
@Service
@Slf4j
public class CultivatingPrizeServiceImpl implements CultivatingPrizeService {

    @Autowired
    public CultivatingPrizeMapper cultivatingPrizeMapper;

    @Override
    public R<List<CultivatingPrize>> getCultivatingPrizeList() {
        log.info("shop-mall[]CultivatingPrizeServiceImpl[]getCultivatingPrizeList[]input.param.query:");

        List<CultivatingPrize> cultivatingPrizeList = cultivatingPrizeMapper.getCultivatingPrizeList();

        return R.ok(cultivatingPrizeList);
    }

    @Override
    public R<Boolean> setAward(SetCultivatingVo setVo) {
        log.info("shop-mall[]CultivatingPrizeServiceImpl[]setAward[]input.param.setVo:" + setVo);
        if (null == setVo || null == setVo.getUserLevel() || null == setVo.getPrizeAward()) {
            return R.error("入参不能为空!");
        }

        //获取等级培育奖信息
        CultivatingPrize cultivatingPrize = cultivatingPrizeMapper.getcultivatingPrizeByUserLevel(setVo.getUserLevel());
        if (null == cultivatingPrize) {
            return R.error("该等级无培育奖金额，请联系管理员确认!");
        }

        cultivatingPrize.setCultivatingPrize(setVo.getPrizeAward());
        int count = cultivatingPrizeMapper.edit(cultivatingPrize);
        if (count == 0) {
            return R.error("设置培育奖金额失败!");
        }

        return R.ok(0, true);
    }
}
